现在的位置: 首页 > 综合 > 正文

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

2018年08月27日 ⁄ 综合 ⁄ 共 731字 ⁄ 字号 评论关闭

 

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;
		}
	}
}

 

 

 

抱歉!评论已关闭.