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

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

相关推荐
九章云极AladdinEdu9 小时前
绿色算力技术栈:AI集群功耗建模与动态调频系统
人工智能·pytorch·深度学习·unity·游戏引擎·transformer·gpu算力
伽蓝_游戏14 小时前
UGUI源码剖析(15):Slider的运行时逻辑与编辑器实现
游戏·ui·unity·性能优化·c#·游戏引擎·.net
lrh302521 小时前
Custom SRP - Complex Maps
unity·srp·render pipeline
m0_497214151 天前
unity中通过拖拽,自定义scroll view中子物体顺序
unity·游戏引擎
地狱为王1 天前
在Unity中实现DTLN-AEC处理音频文件的功能
unity·aec·降噪
SmalBox1 天前
【URP】Shader绘制棋盘格对比内置管线
unity·渲染
郝学胜-神的一滴2 天前
基于OpenGL封装摄像机类:视图矩阵与透视矩阵的实现
c++·qt·线性代数·矩阵·游戏引擎·图形渲染
EQ-雪梨蛋花汤2 天前
【Unity笔记】Unity 编辑器扩展:打造一个可切换 Config.assets 的顶部菜单插件
unity·编辑器·游戏引擎
SmalBox2 天前
【URP】UnityHLSL顶点片元语义详解
unity·渲染
在路上看风景3 天前
9. Mono项目与Unity的关系
unity