当前位置: 首页 > article >正文

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

1、切换到动画器

在这里插入图片描述
点击make transition和exit关联起来

2、设置参数

在这里插入图片描述
勾选掉Has Exit Time

3、脚本给动画器传参

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);
    }
}


http://www.kler.cn/a/162541.html

相关文章:

  • 机器学习-分类问题
  • Tmux中使用Docker报错 - 解决方案
  • Windows下使用CMD修改本地IP
  • SQL自学通之简介
  • PyQt6 QTimeEdit时间控件
  • YOLOv5独家原创改进:SPPF自研创新 | SPPF与感知大内核卷积UniRepLK结合,大kernel+非膨胀卷积提升感受野
  • 7天用Go实现分布式缓存
  • 简谈MySQL的binlog模式
  • ALTERNET STUDIO 9.1 Crack
  • 啃下这50道笔试题,你就是SQL专家!(附答案,收藏备用)
  • 元宇宙vr党建云上实景展馆扩大党的影响力
  • 将 ONLYOFFICE 协作空间的公共房间嵌入到网页
  • 复杂sql分析 以及 索引合并
  • 使用异或查找数组中出现奇数次的唯一或唯二数字
  • Vue.directive
  • Python 数据分析:日期型数据的玩转之道
  • 混合预编码(Hybrid Precoding)的全连接结构与子连接结构
  • 什么是自动化测试框架?常用的自动化测试框架有哪些?
  • Springboot之配置文件(.yml)【搬代码】
  • 基于Docker安装Mysql:5.5