unity 2d 入门 飞翔小鸟 柱子移动(十一)

c#脚本

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PoleMove : MonoBehaviour
{
    //移动上限制
    public float up;
    //移动下限
    public float below;
    //速度
    private float speed;
    // Start is called before the first frame update
    void Start()
    {
        speed = Random.Range(0.5f, 2.5f);
    }

    // Update is called once per frame
    void Update()
    {
        if (transform.position.y>up)
        {
            speed = -speed;
        }
        if (transform.position.y < below)
        {
            speed = -speed;
        }
        //让柱子上限移动
        transform.position = new Vector3(transform.position.x, transform.position.y + speed * Time.deltaTime, transform.position.z);
    }
}

创建空的图层,并把柱子拖拽到同个图层下

给pole拖拽添加脚本

相关推荐
神秘的土鸡4 小时前
【CS创世SD NAND征文】为无人机打造可靠数据仓:工业级存储芯片CSNP32GCR01-AOW在飞控系统中的应用实践
嵌入式硬件·游戏引擎·无人机·cocos2d·雷龙
jtymyxmz21 小时前
《Unity Shader》6.4.3 半兰伯特模型
unity·游戏引擎
AA陈超21 小时前
ASC学习笔记0001:处理目标选择系统中当Actor拒绝目标确认时的调用
c++·笔记·学习·游戏·ue5·游戏引擎·虚幻
我的golang之路果然有问题1 天前
mac配置 unity+vscode的坑
开发语言·笔记·vscode·macos·unity·游戏引擎
于小汐在咯1 天前
【虚拟现实技术】在Unity里创建一个简单的AR项目
unity·ar·vr
HahaGiver6661 天前
Unity Shader Graph 3D 实例 - 一个简单的红外线扫描全身效果
3d·unity·游戏引擎
o***Z4481 天前
免费的WebAssembly游戏引擎,AssemblyScript
游戏引擎·wasm
雪下的新火2 天前
Blender:法线图&黑白图
游戏·unity·游戏引擎·blender·笔记分享
HahaGiver6662 天前
从0到1做一个“字母拼词”Unity小游戏(含源码/GIF)- 实现多单词顺序通关进度逻辑
unity·游戏引擎·游戏程序
Dr.勿忘2 天前
Unity一分钟思路---UI任务条:宝箱位置如何准确卡在百分比位置上
ui·unity·游戏程序·屏幕适配