using System.Collections; using System.Collections.Generic; using UnityEngine; public class GuangkejiAnimator : MonoBehaviour { public Animator anim; private float startTimer; private bool isStart;//动画是否开始播放 public Animator Line;//线条动画组件 public GameObject fanguang;//反光动画 public GameObject[] textGamesLisr; private bool isLook;//是否看着对象 private void Start() { //anim = this.GetComponent(); startTimer = 2f; ShowOrHeidGames(-1); } private void ShowOrHeidGames(int index) { for (int i = 0; i < textGamesLisr.Length; i++) { if (i == index)//如果等于传入的参数 { PlaySounds(i); textGamesLisr[i].SetActive(true); //文字动画的三个动画组件 textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame").GetComponent().Play("frame_Appear"); textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (2)").GetComponent().Play("frame_Appear"); textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (1)").GetComponent().Play("frame_Appear"); } else { StartCoroutine(WaitForTiemrs(0.8f, textGamesLisr[i])); textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame").GetComponent().Play("frame_Disappear"); textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (2)").GetComponent().Play("frame_Disappear"); textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (1)").GetComponent().Play("frame_Disappear"); } } } /// /// 线条动画开始 /// public void LineStart() { Line.gameObject.GetComponent().enabled = true;//获取线条的组件 Line.gameObject.GetComponent().enabled = true;//获取线条动画的组件 fanguang.gameObject.SetActive(true); Line.speed = 1;//播放动画 } /// /// 线条动画暂停 /// public void LineStop() { Line.gameObject.GetComponent().enabled = false; Line.gameObject.GetComponent().enabled = false; fanguang.gameObject.SetActive(false); Line.speed = 0;//暂停动画 } /// /// 机械臂的动画开始 /// public void AnimStart() { anim.speed = 1f; } /// /// 机械臂的动画停止 /// public void AnimStop(int index) { ShowOrHeidGames(index); anim.speed = 0; isStart = true; } private void Update() { if (isStart) { startTimer -= Time.deltaTime;//开始时间倒计时 if (startTimer <= 0) { AnimStart(); startTimer = 4; ShowOrHeidGames(-1);//不播放文字动画 isStart = false; } } } IEnumerator WaitForTiemrs(float timer, GameObject obj) { yield return new WaitForSeconds(timer); // obj.SetActive(false); } private void PlaySounds(int Soundindex) { string soundNames = ""; switch (Soundindex) { case 0: soundNames = "GY_GKJ1"; break; case 1: soundNames = "GY_GKJ2"; break; case 2: soundNames = "GY_GKJ3"; break; case 3: soundNames = "GY_GKJ4"; break; case 4: soundNames = "GY_GKJ5"; break; case 5: soundNames = "GY_GKJ6"; break; } AudioManager.Instance.AudioGongYe_GKJ_LanguageSounds(soundNames); } }