untiy3D为游戏物体制作简单的动画
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 created
void Start()
{
// 获取动画器组件
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)) {
animator.Play("left");
}
}
}
效果
20250212_152204