untiy3D为游戏物体制作简单的动画

1.创建一个物体挂载动画组件Animator

2.创建一个动画控制器

3.动画控制器挂载到Animator组件

4.创建动画窗口>动画

入口默认执行left

执行效果

20250212_151707

脚本控制动画

鼠标点击是切换到动画t

csharp 复制代码
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

相关推荐
学长毕设11 小时前
基于SpringBoot的游戏攻略社区交流系统-附源码
spring boot·后端·游戏
一只大鸽子14 小时前
游戏开发笔记7-Godot RPG游戏基础-场景切换、全局脚本
笔记·游戏·godot
赤生云电竞16 小时前
云游戏边缘节点部署实践:机房选址与网络拓扑选型
网络·游戏·php
芝麻粒儿17 小时前
Scratch少儿编程案例-鼠标控制练习
游戏·青少年编程·计算机外设·scratch·少儿编程
科技小登17 小时前
DDoS防护选型测评:高防CDN、高防IP与SDK游戏盾怎么做同口径POC?
tcp/ip·游戏·ddos
xx z2 天前
打开游戏提示 d3dx9_43.dll 缺失怎么办(DirectX 修复步骤)
windows·游戏·工具·软件
珍猪吃饲料2 天前
消息丢了、重复消费了,MQ 这套账该怎么算
游戏
芝麻粒儿3 天前
Scratch少儿编程案例-多人联机与IO游戏(1)
游戏·青少年编程·scratch·少儿编程
赤生云电竞4 天前
云游戏边缘节点部署:机房选址与网络拓扑优化实践 —— 从80ms时延预算看节点落位与Spine-Leaf组网
服务器·游戏·spine