I have 20 mesh objects and I want to slowly (every 1 second or so) make each one inactive when the user inputs the R-KEY. My first thought was the code below, but it isn’t working and I’m guessing it is because the function is in the Update() function. Anyone have any suggestions?
In case it helps to look at the project, I am working on the visualization in the below link and want to make the spiral disappear slowly and reappear in a similar way.
using UnityEngine;
using System.Collections;
public class MeshlAnimation : MonoBehaviour {
int n = 20; // number of mesh objects
void Update ()
{
if ( Input.GetKey(KeyCode.R) )
{
ToggleActiveGameObjects();
}
}
void ToggleActiveGameObjects( )
{
foreach ( Transform meshObj in GetComponentsInChildren<Transform>() )
{
StartCoroutine(InputDelay(meshObj));
}
}
IEnumerator InputDelay( Transform meshObj )
{
meshObj.gameObject.active = false;
yield return new WaitForSeconds(.5f);
}
}
float timeAccumilator = 0f;
float triggerAtTime = 1f;
int nextToUpdate = 0;
List listOfThingsToUpdate
on Update:
timeAccumilator += Time.deltaTime;
if timeAccumilator > triggerAtTime
then
DoSlowFunctionTo(listOfThingsToUpdate[nextToUpdate] )
nextToUpdate++;
end
end