【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处取消激活动画(在运行时通过按钮激活)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值