【Unity】做了个刻晴跳舞的小Demo,记录下按钮控制多模型骨骼动画播放
1、提前准备好6个绑定好骨骼动画的刻晴模型,布置好场景
2、创建KeQing脚本,接收6个模型
public bool start = false;//判断模型骨骼动画播放状态
public GameObject animobj1;
public GameObject animobj2;
public GameObject animobj3;
public GameObject animobj4;
public GameObject animobj5;
public GameObject animobj6;//接收6个模型
3、创建开始播放和暂停播放的函数(这个我是把每一个模型上的动画状态启动或关闭)
void open()//开始播放
{
animobj1.GetComponent<Animator>().enabled = true;
animobj2.GetComponent<Animator>().enabled = true;
animobj3.GetComponent<Animator>().enabled = true;
animobj4.GetComponent<Animator>().enabled = true;
animobj5.GetComponent<Animator>().enabled = true;
animobj6.GetComponent<Animator>().enabled = true;
}
void off()//暂停播放
{
animobj1.GetComponent<Animator>().enabled = false;
animobj2.GetComponent<Animator>().enabled = false;
animobj3.GetComponent<Animator>().enabled = false;
animobj4.GetComponent<Animator>().enabled = false;
animobj5.GetComponent<Animator>().enabled = false;
animobj6.GetComponent<Animator>().enabled = false;
}
4、建立一个函数,使其挂在到按钮上,点击时播放或者暂停播放
public void a_Tiaowu1()
{
//animobj.GetComponent<Animation>().Play("Tiaowu1");
//m_Anim.SetBool("Tiaowu1", true);
//animobj.SetActive(true);
start = !start;
if(start == false)
{
off();//停止播放
}
if (start == true)
{
open();//开始播放
}
}
建一个空对象,将脚本挂载上
在UI的按钮上指定点击触发的函数
5、最后不要忘记,在模型的Animator处取消激活动画(在运行时通过按钮激活)
Love for Ever Day
本文作者:HanaKoo
本文链接:https://www.cnblogs.com/HanaKoo/p/18271415
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步