| | | 1 | | using System.Collections; |
| | | 2 | | using UnityEngine; |
| | | 3 | | |
| | | 4 | | public class AudienceController : MonoBehaviour |
| | | 5 | | { |
| | | 6 | | public GameObject[] puppets; |
| | | 7 | | public AudioSource[] crowdAudioSources; |
| | | 8 | | public Transform player; |
| | | 9 | | public RuntimeAnimatorController celebrationAnimator; |
| | | 10 | | public AudioClip celebrationSoundClip; |
| | | 11 | | public AudioClip crowdCelebrationSoundClip; |
| | 2 | 12 | | private bool celebrating = false; |
| | | 13 | | public FadeController fadeController; |
| | | 14 | | |
| | | 15 | | private void Start() |
| | 1 | 16 | | { |
| | 1 | 17 | | celebrating = false; |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | private void Update() |
| | 22125 | 21 | | { |
| | 22125 | 22 | | if(celebrating) |
| | 21949 | 23 | | { |
| | 175592 | 24 | | for (int i = 0; i < puppets.Length; i++) |
| | 65847 | 25 | | { |
| | 65847 | 26 | | Quaternion rot = Quaternion.LookRotation(player.position - puppets[i].transform.position); |
| | 65847 | 27 | | puppets[i].transform.rotation = Quaternion.Slerp(puppets[i].transform.rotation, rot, Time.deltaTime); |
| | 65847 | 28 | | } |
| | 21949 | 29 | | } |
| | 22125 | 30 | | } |
| | | 31 | | |
| | | 32 | | public void StartVictory() |
| | 1 | 33 | | { |
| | 1 | 34 | | StartCoroutine(StartVictorySequence()); |
| | 1 | 35 | | } |
| | | 36 | | |
| | | 37 | | private IEnumerator StartVictorySequence() |
| | 1 | 38 | | { |
| | 1 | 39 | | Celebrate(); |
| | 1 | 40 | | yield return new WaitForSeconds(10f); |
| | 1 | 41 | | fadeController.FadeOut(); |
| | 0 | 42 | | yield return new WaitForSeconds(1f); |
| | 0 | 43 | | SceneController.GoToMenuScene(); |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | public void Celebrate() |
| | 1 | 47 | | { |
| | 1 | 48 | | celebrating = true; |
| | 8 | 49 | | for (int i=0; i < puppets.Length; i++) |
| | 3 | 50 | | { |
| | 3 | 51 | | Animator anim = puppets[i].GetComponent<Animator>(); |
| | 3 | 52 | | AudioSource audio = puppets[i].GetComponent<AudioSource>(); |
| | 3 | 53 | | Quaternion targetRotation = Quaternion.LookRotation(player.position - puppets[i].transform.position); |
| | | 54 | | |
| | 3 | 55 | | anim.runtimeAnimatorController = celebrationAnimator; |
| | 3 | 56 | | audio.Stop(); |
| | 3 | 57 | | audio.clip = celebrationSoundClip; |
| | 3 | 58 | | audio.loop = true; |
| | 3 | 59 | | audio.volume = 0.8f; |
| | 3 | 60 | | audio.Play(); |
| | 3 | 61 | | } |
| | 8 | 62 | | for (int i = 0; i < crowdAudioSources.Length; i++) |
| | 3 | 63 | | { |
| | 3 | 64 | | AudioSource audio = crowdAudioSources[i]; |
| | 3 | 65 | | audio.Stop(); |
| | 3 | 66 | | audio.clip = crowdCelebrationSoundClip; |
| | 3 | 67 | | audio.loop = true; |
| | 3 | 68 | | audio.volume = 0.7f; |
| | 3 | 69 | | audio.Play(); |
| | 3 | 70 | | } |
| | 1 | 71 | | } |
| | | 72 | | } |