济南企业网站制,对购物网站建设的建议,wordpress里的模板,django做的网站1、给地面#xff0c;柱体这种添加2d盒装碰撞器#xff0c;小鸟移动碰到就不会动了 2、修改小鸟的脚本#xff08;脚本命名不规范#xff0c;不要在意#xff09;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Fly : Mo…1、给地面柱体这种添加2d盒装碰撞器小鸟移动碰到就不会动了 2、修改小鸟的脚本脚本命名不规范不要在意
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 GetComponentRigidbody2D();animator GetComponentAnimator();}// 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);}
}小鸟挥动翅膀动画停止
见下一个章节