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

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

相关推荐
风酥糖12 小时前
Godot游戏练习01-第20节-增加亿点点细节
游戏·游戏引擎·godot
智算菩萨14 小时前
【OpenGL】6 真实感光照渲染实战:Phong模型、材质系统与PBR基础
开发语言·python·游戏引擎·游戏程序·pygame·材质·opengl
心前阳光18 小时前
Unity之ScrollRect简易实现
unity·游戏引擎
WarrenMondeville19 小时前
9.Unity面向对象-对象池
unity
KaGme1 天前
生成3DGS场景在unity中的呈现
3d·unity·游戏引擎
zyh______1 天前
关于unity的序列化
unity·游戏引擎
weixin_409383121 天前
godot碰撞测试的学习
学习·游戏引擎·godot
电子云与长程纠缠1 天前
Godot学习06 - AnimationPlayer内置动画
学习·游戏引擎·godot
星夜泊客2 天前
C# : 引用类型都存在堆上吗
unity·c#
点量云实时渲染-小芹2 天前
Unity模型数字孪生虚拟仿真webgl推流卡实时云渲染推流
unity·webgl·数字孪生·实时云渲染·虚拟仿真·云推流