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