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

新建c#脚本

csharp 复制代码
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);
    }
}

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

相关推荐
RReality1 小时前
【Unity UGUI】Toggle / ToggleGroup 与 Dropdown
ui·unity·游戏引擎·图形渲染·材质
雪儿waii2 小时前
Unity 中的 InvokeRepeating 详解
unity·游戏引擎
mxwin2 小时前
Unity Shader 程序化生成:Shader 中的数学宇宙
unity·游戏引擎
雪儿waii3 小时前
Unity 中的 Quaternion(四元数)详解
unity·游戏引擎
RReality4 小时前
【Unity UGUI】ScrollRect 与 Scrollbar 深度用法
unity·游戏引擎
人邮异步社区4 小时前
如何自学游戏引擎的开发?
unity·程序员·游戏引擎
郝学胜-神的一滴5 小时前
[简化版 Games 101] 计算机图形学 05:二维变换下
c++·unity·图形渲染·three.js·opengl·unreal
mxwin18 小时前
Unity URP 热更新兼容性:Shader 在 IL2CPP 打包下的注意事项
unity·游戏引擎
mxwin1 天前
Unity shader中TransformWorldToShadowCoord原理解析
unity·游戏引擎·shader
mxwin1 天前
Unity Shader 中 ShadowCaster的作用和疑问
unity·游戏引擎