using UnityEngine; using System.Collections; public class PlayAminitors : MonoBehaviour { public GameObject gaminitor; public RuntimeAnimatorController controller1,controller2; //动画 public AudioSource audioSource1,audioSource2; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKey (KeyCode.Alpha1)) { //找到动画组件的Animator组件,获得cotroler属性,修改为controller1 gaminitor.GetComponent<Animator>().runtimeAnimatorController = controller1; //播放声音 if(!audioSource1.isPlaying) audioSource1.Play(); }else if(Input.GetKey (KeyCode.Alpha0)){ //设置为null,则动画停止 gaminitor.GetComponent<Animator>().runtimeAnimatorController = null; }else if(Input.GetKey (KeyCode.Alpha2)){ gaminitor.GetComponent<Animator>().runtimeAnimatorController = controller2; } } }