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