1.创建一个物体挂载动画组件Animator
2.创建一个动画控制器
3.动画控制器挂载到Animator组件
4.创建动画窗口>动画
入口默认执行left
执行效果
20250212_151707
脚本控制动画
鼠标点击是切换到动画t
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class test : MonoBehaviour
{private Animator animator;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){// 获取动画器组件animator = GetComponent<Animator>();}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)) {animator.Play("left");}}
}
效果
20250212_152204