RESPAWNER

This commit is contained in:
Rizvee committed 2022-02-26 02:11:59 -06:00
1 parent 0629824797
commit e1da79c14e
4 files changed
+16 -7

No files matched your search

+9 -5
View File
@@ -7,7 +7,6 @@ public class SpawnTrigger : Trigger
[SerializeField] float despawnTimer = 10f;
[SerializeField] GameObject entity;
[SerializeField] Vector2 startPos;
private GameObject clone;
private bool spawned;
[SerializeField] bool respawns = false;
[SerializeField] float respawnTime = 3f;
@@ -17,11 +16,15 @@ public class SpawnTrigger : Trigger
//And function itself
IEnumerator SpawnDespawn(){
GameObject clone;
clone = Instantiate(entity, startPos, Quaternion.identity);
clone.gameObject.SetActive(true);
yield return new WaitForSeconds(despawnTimer);
Destroy(clone);
this.gameObject.SetActive(false);
if(!respawns) {
this.gameObject.SetActive(false);
}
}
public override void Action() {
if(!spawned && !respawns) {
@@ -29,10 +32,11 @@ public class SpawnTrigger : Trigger
StartCoroutine(SpawnDespawn());
}
else if(respawns) {
if(elapsed < respawnTime) {
elapsed += Time.deltaTime;
if(elapsed > respawnTime) {
elapsed = 0;
StartCoroutine(SpawnDespawn());
StartCoroutine(SpawnDespawn());
}
}
}