using UnityEngine; public class ButtonAxisLock : MonoBehaviour { public Transform buttonDirectionRoot; public float minX = 0f; public float maxX = 0.02f; public float minY = 0f; public float maxY = 0f; public float minZ = 0f; public float maxZ = 0f; void Update() { Vector3 localPos = buttonDirectionRoot.InverseTransformPoint(transform.position); localPos.x = Mathf.Clamp(localPos.z, minX, maxX); localPos.y = Mathf.Clamp(localPos.z, minY, maxY); localPos.z = Mathf.Clamp(localPos.z, minZ, maxZ); transform.position = buttonDirectionRoot.TransformPoint(localPos); } }