ゲーム オブジェクトの y の値を 4 と -4 にクランプしようとしていますが、ymax と ymin にジャンプし続けます。私が考えることができる唯一の理由は、最後の行コードのためです。ゲームでは x 値と z 値が変更されないため、y 値のみをクランプしています。ゲームはポンに似ています。
using UnityEngine;
using System.Collections;
public class Movement1 : MonoBehaviour
{
public Vector3 Pos;
void Start ()
{
Pos = gameObject.transform.localPosition;
}
public float yMin, yMax;
void Update ()
{
if (Input.GetKey (KeyCode.W)) {
transform.Translate (Vector3.up * Time.deltaTime * 10);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (Vector3.down * Time.deltaTime * 10);
}
Pos.y = Mathf.Clamp(Pos.y,yMin,yMax);
gameObject.transform.localPosition = Pos;
}
}