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 updatevoid Start(){bird = GetComponent<Rigidbody2D>();animator = GetComponent<Animator>();}// Update is called once per framevoid 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;//向动画器传送为life的参数animator.SetBool("life", false);}
}
见下一个章节
本文发布于:2024-02-01 05:53:11,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170673799334371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |