unity3d 如何用GUI按钮播放动画脚本怎么写
需要一个UI按钮控制动画播放的脚本。用OnGUI生成按钮,按下play1后播放名为anim1的Clips动画,按下play2后播放anim2的Clips动画,按下play...
需要一个UI按钮控制动画播放的脚本。用OnGUI生成按钮,按下play1后播放名为anim1的Clips动画,按下play2后播放anim2的Clips动画,按下play3后播放xxxx的Clips动画……,脚本我写了一些了但是提示Animation未包含Play定义,请问这脚本应该怎么写。
using UnityEngine;
public class AnimPlay : MonoBehaviour
{
public Animation anim;
void Start()
{
anim = gameObject.GetComponent<Animation>();
}
void OnGUI()
{
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.01f,
Screen.width * 0.1f, Screen.height * 0.1f), "play1"))
{
anim.Play("anim1");
}
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.11f, Screen.width * 0.1f, Screen.height * 0.1f), "play2"))
{
anim.Play("anim2");
}
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.21f, Screen.width * 0.1f, Screen.height * 0.1f), "play3"))
{
anim.Play("anim3");
}
}
} 展开
using UnityEngine;
public class AnimPlay : MonoBehaviour
{
public Animation anim;
void Start()
{
anim = gameObject.GetComponent<Animation>();
}
void OnGUI()
{
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.01f,
Screen.width * 0.1f, Screen.height * 0.1f), "play1"))
{
anim.Play("anim1");
}
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.11f, Screen.width * 0.1f, Screen.height * 0.1f), "play2"))
{
anim.Play("anim2");
}
if (GUI.Button(new Rect(Screen.width * 0.01f, Screen.height * 0.21f, Screen.width * 0.1f, Screen.height * 0.1f), "play3"))
{
anim.Play("anim3");
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询