mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-10-11 18:19:11 +00:00
did a minor tweak
This commit is contained in:
1 parent
8f2a693284
commit
11a2af2f5f
302 files changed
+1022
-167
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
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;
|
||||
private float elapsed = 0f;
|
||||
|
||||
|
||||
|
||||
//And function itself
|
||||
IEnumerator SpawnDespawn(){
|
||||
clone = Instantiate(entity, startPos, Quaternion.identity);
|
||||
clone.gameObject.SetActive(true);
|
||||
yield return new WaitForSeconds(despawnTimer);
|
||||
Destroy(clone);
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
public override void Action() {
|
||||
if(!spawned && !respawns) {
|
||||
Debug.Log("spawn");
|
||||
StartCoroutine(SpawnDespawn());
|
||||
}
|
||||
else if(respawns) {
|
||||
if(elapsed < respawnTime) {
|
||||
elapsed = 0;
|
||||
|
||||
StartCoroutine(SpawnDespawn());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user