unity 2d 入门 飞翔小鸟 小鸟跳跃 碰撞停止挥动翅膀动画(十)

1、切换到动画器

点击make transition和exit关联起来

2、设置参数

勾选掉Has Exit Time

3、脚本给动画器传参

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fly : MonoBehaviour
{
    //获取小鸟(刚体)
    private Rigidbody2D bird;
    //速度
    public float speed;
    //跳跃
    public float jump;
    //是否存活
    public static bool life = true;
    //获取动画器
    private Animator animator;

    // Start is called before the first frame update
    void Start()
    {
        bird = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        //村换的时候才能运动
        if (life) { 
            bird.velocity = new Vector2(speed, bird.velocity.y);
            //鼠标点击给目标一个纵向速度
            if (Input.GetMouseButtonDown(0))
            {
                bird.velocity = new Vector2(bird.velocity.x, jump);
            }
        }
    }
    //如果碰撞器撞到了某个物体
    private void OnCollisionEnter2D(Collision2D collision)
    {
        life = false;
        animator.SetBool("life", false);
    }
}
相关推荐
爱搞虚幻的阿恺2 小时前
Niagara粒子系统-超炫酷的闪电特效(第二期 旋转的纸片)
游戏·游戏引擎·虚幻
WarPigs8 小时前
Unity渲染问题记录
unity·游戏引擎
不绝1918 小时前
导入3D模型时相关参数设置/Model标签页/Rig标签页/Avatar相关参数/Animation标签页/Materia标签页
unity·游戏程序
dlpay11 小时前
使用blender搭建模型并导入godot游戏引擎
游戏引擎·godot·blender
不是AI11 小时前
【Unity开发】一、在安卓设备上运行Unity项目
android·unity·游戏引擎
淡海水1 天前
【节点】[EyeSurfaceTypeDebug节点]原理解析与实际应用
unity·游戏引擎·debug·shadergraph·图形·surface·eye
淡海水1 天前
【节点】[IrisLimbalRing节点]原理解析与实际应用
unity·游戏引擎·iris·shadergraph·图形·ring·limbal
在路上看风景1 天前
33. RenderTarget
unity
在路上看风景1 天前
34. GPU偏爱2的幂次
unity
Zik----1 天前
Unity的基础使用
unity·游戏引擎