blob: 0834f3277c14ff93462479a45c99408f0aea07a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}
}
}
|