Hi everyone ![]()
I’m asking for help on a particular issue.
I want to have a cube, which is grey to begin, and we wait on that for a random amount of time between 6 & 7 seconds.
I then want the coroutine to kick in and cause a checkerboard flash between 2 textures for 2 - 3 seconds.
I then want it to go back and repeat this kind of pattern. A finite state machine was recommended to me but I’m at a total loss where to begin - started learning a month ago for a project and I’m in way over my head. The code I have is here (apologies for it being so all over the place). If anyone can tell me how to alter what I have to make it do what I want,I’d be grateful. ![]()
public class FSM : MonoBehaviour {
public float freq ; // this is a Period. We convert to freq on line 23
public Texture[] textures; // texture 1 and 2 declared here
void Start ()
{
StartCoroutine (DoTextureLoop ()); //Begins the loop
}
IEnumerator DoTextureLoop(){
int i = 0;
while (true) { //while the i = 0, we render the first texture. When it changes to 1, swap textures.
GetComponent<Renderer> ().material.mainTexture = textures [i];
i = (i + 1) % textures.Length;
yield return new WaitForSeconds (1f / freq);
}
}
void Update () {
if (Time.deltaTime > 10) {
StopCoroutine (DoTextureLoop () );
}
}
}