public IEnumerator Move() { int i = 0; while (true) { float time = 0; while (time < movement[i].w) { eyes.transform.localPosition = new Vector3(body.velocity.x / 50, (scale.transform.localScale.y - 1) / 2, 0); time += Time.deltaTime; yield return(null); } MoveTrigger trigger = new MoveTrigger(); trigger.group = gameObject; trigger.x = movement[i].x; trigger.y = movement[i].y; trigger.duration = movement[i].z; trigger.easing = easing; trigger.userigidbody = true; trigger.Initialize(); StartCoroutine(trigger.Move()); time = 0; while (time < movement[i].z) { eyes.transform.localPosition = new Vector3(body.velocity.x / 50, (scale.transform.localScale.y - 1) / 2, 0); time += Time.deltaTime; yield return(null); } eyes.transform.localPosition = new Vector3(body.velocity.x / 50, (scale.transform.localScale.y - 1) / 2, 0); i++; if (i >= movement.Length) { i = 0; } yield return(null); } }
public IEnumerator Begin() { int i = 0; if (exe == (ExecutionType)0) //Sequential { while (i < triggers.Length) { float d1 = delay[i], time = 0, d2 = 0; GameObject trigger = triggers[i]; while (time <= d1) { time += Time.deltaTime; yield return(null); } switch (trigger.gameObject.tag) { // MOVE TRIGGER case "MoveTrigger": MoveTrigger move = trigger.GetComponent <MoveTrigger>(); d2 = move.getDuration(); time = 0; //Debug.Log("Trigger " + i); StartCoroutine(move.Move()); while (time <= d2 && !ignorefinish) { time += Time.deltaTime; yield return(null); } while (move.getFinished() != true && !ignorefinish) { //Debug.Log("Waiting to finish"); yield return(null); } move.StopAllCoroutines(); break; // SPAWN TRIGGER case "SpawnTrigger": SpawnTrigger spawn = trigger.GetComponent <SpawnTrigger>(); spawn.StopAllCoroutines(); StartCoroutine(spawn.Begin()); if (spawn.exe == ExecutionType.Parallel) { while (spawn.getFinished() != true && !ignorefinish) { //Debug.Log("Waiting to finish"); yield return(null); } } break; // MUSIC TRIGGER case "MusicTrigger": MusicTrigger music = trigger.GetComponent <MusicTrigger>(); d2 = music.getDuration(); time = 0; // Volume if (music.mode == MusicTrigger.Mode.volume) { StartCoroutine(music.setMusicVolume()); while (music.getFinished() != true && !ignorefinish) { //Debug.Log("Waiting to finish"); yield return(null); } } // Change Song else if (music.mode == MusicTrigger.Mode.music) { music.setBGMusic(); } music.StopAllCoroutines(); break; // TOGGLE TRIGGER case "ToggleTrigger": ToggleTrigger toggle = trigger.GetComponent <ToggleTrigger>(); StartCoroutine(toggle.Toggle()); while (toggle.getFinished() != true && !ignorefinish) { //Debug.Log("Waiting to finish"); yield return(null); } break; // COLOR TRIGGER case "ColorTrigger": ColorTrigger color = trigger.GetComponent <ColorTrigger>(); color.SpawnActivate(); while (!color.getFinished() && !ignorefinish) { //Debug.Log("Waiting to finish"); yield return(null); } break; // SHAKE TRIGGER case "ShakeTrigger": ShakeTrigger shake = trigger.GetComponent <ShakeTrigger>(); shake.SpawnActivate(); break; default: break; } i++; if (i == triggers.Length && loop) { i = 0; } yield return(null); } } else if (exe == (ExecutionType)1) //Parallel { finished = false; float longestDelay = 0, time = 0; while (i < triggers.Length) { GameObject trigger = triggers[i]; switch (trigger.gameObject.tag) { // MOVE TRIGGER case "MoveTrigger": MoveTrigger move = trigger.GetComponent <MoveTrigger>(); longestDelay = Mathf.Max(move.getDuration(), longestDelay); //Debug.Log("Trigger " + i); StartCoroutine(move.Move()); break; // SPAWN TRIGGER case "SpawnTrigger": SpawnTrigger spawn = trigger.GetComponent <SpawnTrigger>(); spawn.StopAllCoroutines(); StartCoroutine(spawn.Begin()); break; // MUSIC TRIGGER case "MusicTrigger": MusicTrigger music = trigger.GetComponent <MusicTrigger>(); longestDelay = Mathf.Max(music.getDuration(), longestDelay); // Volume if (music.mode == MusicTrigger.Mode.volume) { StartCoroutine(music.setMusicVolume()); } // Change Song else if (music.mode == MusicTrigger.Mode.music) { music.setBGMusic(); } break; // TOGGLE TRIGGER case "ToggleTrigger": ToggleTrigger toggle = trigger.GetComponent <ToggleTrigger>(); longestDelay = Mathf.Max((toggle.on_targets.Length + toggle.off_targets.Length) * Time.fixedDeltaTime * 10, longestDelay); StartCoroutine(toggle.Toggle()); break; // COLOR TRIGGER case "ColorTrigger": ColorTrigger color = trigger.GetComponent <ColorTrigger>(); color.SpawnActivate(); break; default: break; } i++; } while (time <= longestDelay) { time += Time.deltaTime; yield return(null); } finished = true; } }