本文主要是介绍unity 2d 入门 飞翔小鸟 柱子移动(十一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
c#脚本
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 updatevoid Start(){speed = Random.Range(0.5f, 2.5f);}// Update is called once per framevoid 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拖拽添加脚本
这篇关于unity 2d 入门 飞翔小鸟 柱子移动(十一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!