Unity3D【脚本】获取游戏物体的Animator组件,并且修改动画属性

来源:互联网 发布:matlab 图像配准算法 编辑:程序博客网 时间:2024/06/04 18:32

 

using UnityEngine;using System.Collections;public class PlayAminitors : MonoBehaviour {public GameObject gaminitor;public RuntimeAnimatorController controller1,controller2;//动画public AudioSource audioSource1,audioSource2;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {if (Input.GetKey (KeyCode.Alpha1)) {//找到动画组件的Animator组件,获得cotroler属性,修改为controller1gaminitor.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;}}}


 

 

 

0 0