一个Annimator及脚本控制多个物体动画的播放与切换 您所在的位置:网站首页 animate动作只能执行一个图层 一个Annimator及脚本控制多个物体动画的播放与切换

一个Annimator及脚本控制多个物体动画的播放与切换

2024-07-11 19:23| 来源: 网络整理| 查看: 265

一个Annimator及脚本控制多个物体动画的播放与切换

创建一个空物体,点击Add Component添加Annimator组件,添加脚本组件; 在这里插入图片描述 创建AnnimatorController文件夹,右击创建AnnimatorController; 在这里插入图片描述 新建一个长方体和一个球体; 在这里插入图片描述 创建Annimation文件夹,并创建annimation “cubeMove”; 在这里插入图片描述 双击all.controller,打开Annimator窗口,将“cubeMove”拖到状态机,并右击Make Transition进行连接; 在这里插入图片描述 Annimator窗口中左方点击Paramaters创建bool 变量cubeMove; 在这里插入图片描述 选中New State到CubeMove的线,在Annimator窗口中右方点击加号添加条件; 在这里插入图片描述 点击空物体all对象进入空物体层级,然后点击annimation “cubeMove”,再点击cube对象录制长方体的动画; 按照同样步骤再创建一个球体的动画; 录制动画时注意下方中由cubeMove切换到sphereMove; 在这里插入图片描述 脚本代码如下(实现按键播放):

using System.Collections; using System.Collections.Generic; using UnityEngine; public class play : MonoBehaviour { Animator anniController; // Start is called before the first frame update void Start() { anniController = GetComponent(); } // Update is called once per frame void Update() { PlayAni(); } void PlayAni() { if (Input.GetKey(KeyCode.A)) anniController.SetBool("cubeMove ", true); if (Input.GetKey(KeyCode.B)) anniController.SetBool("sphereMove", true); } }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有