Delay Animator Action in C#?
I'm still fairly new to Unity scripting and though I've done my fair share of reading given the time constraints (need to deliver to client yesterday), I'm afraid I'm hitting a roadblock.
I'm looking for a script that allows me to trigger an animator action after a lapse of time. I have my spawn scripts and they do the trick wonderfully, but I realize they don't work for objects that are already in the scene and just have to wait for a while before being activated, then loop again and again according to a certain interval.
For example, I have a robot arm that needs to wait until a number of boxes pile up in front of it before being triggered and picking them up. It has a simple action attached to it, as per screenshot. Everything is already baked in fbx, timely keyframed and ready to be integrated. Unfortunately the robot fires up on runtime regardless of the script. Is there anything that I can do knowing I'm out of time basically?
To give you an idea, here's the spawn code I'm using through my level for hidden objects that need to appear and reappear at specific intervals. It works great for them, not so much for objects that are already present in the scene.
using UnityEngine;
using System.Collections;
public class BakeryMainSpawn: MonoBehaviour {
public GameObject BakeryBread;
public float startWait;
public float spawnWait;
public Vector3 spawnValues = Vector3.zero;
private int Count = 1;
void Start ()
{
if ((BakeryBread != null) && (Count >0))
{
StartCoroutine (BakeryBread());
}
}
IEnumerator BakeryBread ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < Count; i++)
{
Instantiate (Bakery1Bread, spawnValues, Quaternion.identity);
yield return new WaitForSeconds (spawnWait);
}
}
}
}
Thanks for all your help and patience in advance :)