MegaTankWheels.cs 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 
  2. using UnityEngine;
  3. [ExecuteInEditMode]
  4. public class MegaTankWheels : MonoBehaviour
  5. {
  6. public float radius = 1.0f;
  7. public MegaTracks track;
  8. Vector3 localrot = Vector3.zero;
  9. public float offang = 0.0f;
  10. public MegaAxis axis = MegaAxis.Z;
  11. void Start()
  12. {
  13. localrot = transform.localRotation.eulerAngles;
  14. }
  15. void Update()
  16. {
  17. if ( track )
  18. {
  19. if ( track.shape )
  20. {
  21. MegaSpline spl = track.shape.splines[track.curve];
  22. float len = spl.length;
  23. //float off = len * Mathf.Repeat(track.start * 0.01f, 1.0f);
  24. float off = len * track.start * 0.01f; //, 1.0f);
  25. float ang = (off / (Mathf.PI * 2.0f * radius)) * Mathf.PI * 2.0f * Mathf.Rad2Deg;
  26. ang = Mathf.Repeat(ang, 360.0f);
  27. //Debug.Log("Ang " + ang);
  28. Vector3 rot = localrot;
  29. rot[(int)axis] += ang + offang;
  30. transform.localRotation = Quaternion.Euler(rot);
  31. }
  32. }
  33. }
  34. }