diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-01 09:36:29 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-01 09:36:29 +0800 |
| commit | c2b26c0491886b99f422e830cd9ec1637a4ddc2e (patch) | |
| tree | ec5a2b8aaf2e4568bd7ad59aa812864915bc6bdc /Assets/Scripts/GamePlay/Player/WheelTransforms.cs | |
firstmaster
Diffstat (limited to 'Assets/Scripts/GamePlay/Player/WheelTransforms.cs')
| -rw-r--r-- | Assets/Scripts/GamePlay/Player/WheelTransforms.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Assets/Scripts/GamePlay/Player/WheelTransforms.cs b/Assets/Scripts/GamePlay/Player/WheelTransforms.cs new file mode 100644 index 0000000..0834f32 --- /dev/null +++ b/Assets/Scripts/GamePlay/Player/WheelTransforms.cs @@ -0,0 +1,48 @@ +using System; +using UnityEngine; + +namespace GamePlay.Player +{ + [ExecuteAlways] + public class WheelTransforms : MonoBehaviour + { + [Header("Parameters")] + [Range(0f, 4f)] public float length; + [Range(0f, 4f)] public float width; + [Range(-5f, 5f)] public float offsetX; + [Range(-5f, 5f)] public float offsetZ; + [Range(-5f, 5f)] public float offsetY; + + [Header("Bindings")] + public Transform frontLeft; + public Transform frontRight; + public Transform rearLeft; + public Transform rearRight; + +#if UNITY_EDITOR + private void Update() + { + if (Application.isPlaying) return; + UpdateWheels(); + } +#endif + + private void FixedUpdate() + { + UpdateWheels(); + } + + private void UpdateWheels() + { + frontLeft.localPosition = GetPosition(-1, 1); + frontRight.localPosition = GetPosition(1, 1); + rearLeft.localPosition = GetPosition(-1, -1); + rearRight.localPosition = GetPosition(1, -1); + } + + private Vector3 GetPosition(float axisX, float axisZ) + { + return new Vector3(width / 2 * axisX + offsetX, offsetY, length / 2 * axisZ + offsetZ); + } + } +} |
