mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-09-11 08:17:01 +00:00
RESPAWNER
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ public abstract class Trigger : MonoBehaviour
|
||||
if(forceInteract)
|
||||
{
|
||||
Action();
|
||||
hasOccurred = true;
|
||||
if(!repeatable) {
|
||||
hasOccurred = true;
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,11 +393,13 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
forceInteract: 1
|
||||
repeatable: 0
|
||||
repeatable: 1
|
||||
value: 0
|
||||
despawnTimer: 5
|
||||
entity: {fileID: 1489501924}
|
||||
startPos: {x: 0, y: 0}
|
||||
respawns: 1
|
||||
respawnTime: 1
|
||||
--- !u!61 &814501016
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -11,6 +11,9 @@ EditorUserSettings:
|
||||
RecentlyUsedScenePath-1:
|
||||
value: 22424703114646680e0b0227036c78111b1258192f2d28353e663536ebe73c2cf1a71aecf13f33722c0ce6281d
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-2:
|
||||
value: 22424703114646680e0b0227036c7c0219001c396c1c23233967083debf42d
|
||||
flags: 0
|
||||
vcSharedLogLevel:
|
||||
value: 0d5e400f0650
|
||||
flags: 0
|
||||
|
||||
Reference in New Issue
Block a user