1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2025-02-16 17:03:57 +00:00
gravity-fusion/Assets/Components/BlackHole.cs

58 lines
1.2 KiB
C#
Raw Normal View History

2019-10-05 20:41:07 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(Collider2D))]
public class BlackHole : MonoBehaviour
{
2019-10-07 00:21:35 +02:00
protected float spentMass;
2019-10-05 20:41:07 +02:00
public float Mass {
get {
return rigidbody.mass;
}
set {
rigidbody.mass = value;
2019-10-05 23:50:43 +02:00
Scale = Mathf.Sqrt(Mass / Mathf.PI);
2019-10-05 20:41:07 +02:00
}
}
2019-10-07 00:21:35 +02:00
public float UnspentMass {
get {
return rigidbody.mass - spentMass;
}
set {
spentMass = rigidbody.mass - value;
}
}
2019-10-05 20:41:07 +02:00
public float Scale {
get {
return transform.localScale.x;
}
set {
transform.localScale = new Vector3(value, value, 1);
}
}
protected new Rigidbody2D rigidbody;
protected void Awake() {
rigidbody = GetComponent<Rigidbody2D>();
}
protected void Start() {
Mass = 50;
2019-10-07 00:21:35 +02:00
spentMass = 0;
2019-10-05 20:41:07 +02:00
}
protected void OnTriggerEnter2D(Collider2D other) {
Particle otherParticle = other.GetComponent<Particle>();
if(otherParticle != null) {
Mass += otherParticle.Mass;
Destroy(otherParticle.gameObject);
}
}
}