(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveWall : MonoBehaviour
{
private Vector3 initialPos;
private float currentPosY;
private void Start()
{
initialPos = transform.position;
}
void Update()
{
transform.Translate(0, 0.01f, 0);
currentPosY = transform.position.y;
// Clampを使って、移動できる高さを制限
currentPosY = Mathf.Clamp(currentPosY, initialPos.y, 1.5f);
transform.position = new Vector3(0, currentPosY, initialPos.z);
}
}
(実行結果)
- 指定した高さで移動が停止すれば成功です。