纳金网

标题: 怎样切换角色?或者说,怎样让一个角色消失或出现? [打印本页]

作者: 烟雨    时间: 2013-6-29 05:32
标题: 怎样切换角色?或者说,怎样让一个角色消失或出现?
using UnityEngine;
using System.Collections;

public class switchAni : MonoBehaviour {

GameObject ani1;
GameObject ani2;

// Use this for initialization
void Start () {

ani1 = GameObject.Find ("Run");
ani2 = GameObject.Find ("AttackA");

}

// Update is called once per frame
void Update () {

if (Input.GetKey (KeyCode.Alpha1))
{
ani1.renderer.enabled = false;
ani2.renderer.enabled = true;
ani1.animation.Stop ();
ani2.animation.Play ();
}
else if (Input.GetKey (KeyCode.Alpha2))
{
ani1.renderer.enabled = true;
ani2.renderer.enabled = false;
ani1.animation.Play ();
ani2.animation.Stop ();
}

}
}


这是我参照这里写的:
http://answers.unity3d.com/questions/8632/how-to-change-my-character-during-the-game.html
可是为什么没反应?




欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5