void Update() { //keep track of time currentTime += Time.deltaTime; sinOfTime = Mathf.Sin((currentTime) * Mathf.PI); //waiting for two secs in order to get into sync if (currentTime > 2) { //change whose turn it is if (!incremented && sinOfTime < -0.8) { Oscillation obj = rhythmicObjects[oscillationIndex].GetComponentInParent <Oscillation>(); obj.Deactivate(); if (oscillationIndex < maxObjects - 1) { oscillationIndex++; } else { oscillationIndex = 0; } obj = rhythmicObjects[oscillationIndex].GetComponentInParent <Oscillation>(); obj.Activate(); incremented = true; } else if (incremented && sinOfTime > -0.8) { incremented = false; } } }
// Use this for initialization void Start() { int counter = 0; foreach (Rhythm obj in rhythmicObjects) //for all the rythmic objects { obj.SetMyTurn(counter); //set their turn, they need to be destroyed in the correct order counter++; } Oscillation osc = rhythmicObjects[oscillationIndex].GetComponentInParent <Oscillation>(); osc.Activate(); // move }