Respawners are disabled when their creation exists
This commit is contained in:
@@ -11,6 +11,8 @@ public class BlockIce : MonoBehaviour {
|
||||
public GameObject bombPrefab;
|
||||
public Sprite alternateSprite;
|
||||
|
||||
public Respawner respawner; //can be respawned
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer> ();
|
||||
rigidBody = GetComponent<Rigidbody2D> ();
|
||||
@@ -35,7 +37,9 @@ public class BlockIce : MonoBehaviour {
|
||||
GameObject bomb = Instantiate (bombPrefab);
|
||||
bomb.transform.position = transform.position;
|
||||
bomb.GetComponent<Bomb> ().timer = bombTimer;
|
||||
bomb.GetComponent<Bomb> ().respawner = respawner;
|
||||
}
|
||||
respawner.enabled = true;
|
||||
Destroy (gameObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ public class Bomb : MonoBehaviour {
|
||||
GameObject explosion;
|
||||
public GameObject iceBlockPrefab;
|
||||
|
||||
public Respawner respawner; //this can be respawned
|
||||
|
||||
float birthTime;
|
||||
|
||||
void Awake() {
|
||||
@@ -36,6 +38,7 @@ public class Bomb : MonoBehaviour {
|
||||
GameObject iceBlock = Instantiate (iceBlockPrefab);
|
||||
iceBlock.transform.position = transform.position;
|
||||
iceBlock.GetComponent<BlockIce> ().bombTimer = timer - (Time.time - birthTime);
|
||||
iceBlock.GetComponent<BlockIce> ().respawner = respawner;
|
||||
Destroy (gameObject);
|
||||
}
|
||||
|
||||
@@ -50,6 +53,7 @@ public class Bomb : MonoBehaviour {
|
||||
yield return new WaitForSeconds (delay);
|
||||
explosion.SetActive (true);
|
||||
transform.DetachChildren ();
|
||||
respawner.enabled = true;
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,23 @@ public class Respawner : MonoBehaviour {
|
||||
instance.SetActive (true);
|
||||
instance.transform.position = startPos;
|
||||
timer = float.NegativeInfinity;
|
||||
|
||||
//what is it?
|
||||
if (instance.GetComponent<Bomb>() != null) {
|
||||
instance.GetComponent<Bomb> ().respawner = this;
|
||||
}
|
||||
|
||||
if (instance.GetComponent<BlockIce>() != null) {
|
||||
instance.GetComponent<BlockIce> ().respawner = this;
|
||||
}
|
||||
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
if (timer != float.NegativeInfinity) {
|
||||
timer = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user