unity 2d 入门 飞翔小鸟 飞翔脚本(五)

新建c#脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fly : MonoBehaviour
{
    
    
    //获取小鸟(刚体)
    private Rigidbody2D bird;
    //速度
    public float speed;

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

    }

    // Update is called once per frame
    void Update()
    {
    
    
        bird.velocity = new Vector2(speed, bird.velocity.y);
    }
}

将脚本拉动至小鸟图层里面

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43205308/article/details/134843940