I have this script that creates a puddle for every 0.5 seconds. Though when the script gets to “yield return new WaitForSeconds()”, it just stops right there. The rest of the FixedUpdate works but the CreatePuddle() is broken because of the WaitForSeconds(). Here’s the script:
using UnityEngine;
using System.Collections;
public class SlimeScript : EnemyScripts {
//===========//
//[VARIABLES]//
//===========//
//Public Variables
public GameObject puddle; //Puddle prefab
public float delay; //Delay between puddle creations
//Private variables
bool canCreatePuddle = true; //Can the script create another puddle?
//===========//
//[FUNCTIONS]//
//===========//
//Creates a puddle
IEnumerator CreatePuddle(){
canCreatePuddle = false;
//Instantiate a puddle and sets the values
Vector3 pos = new Vector3 (transform.position.x,transform.position.y,transform.position.z);
GameObject newPuddle = Instantiate (puddle,pos,Quaternion.Euler(Vector3.zero)) as GameObject;
newPuddle.transform.parent = transform.parent;
newPuddle.GetComponent<DamageDealer> ().damage = damage;
newPuddle.GetComponent<DamageDealer> ().friendly = false;
//Delay
print ("Created puddle");
yield return new WaitForSeconds (0f);
print ("Create new puddle");
//Allow the script create another puddle
canCreatePuddle = true;
}
public override void FixedUpdate(){
base.FixedUpdate (); //Does everything that's in the base's FixedUpdate()
//Create's a puddle
if (canCreatePuddle)
StartCoroutine (CreatePuddle());
print ("Done");
}
}
UPDATE: - YouTube. I’m still with the issue. I removed the enemy from the level and it worked.