You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.Utility
  4. {
  5. public class AutoMoveAndRotate : MonoBehaviour
  6. {
  7. public Vector3andSpace moveUnitsPerSecond;
  8. public Vector3andSpace rotateDegreesPerSecond;
  9. public bool ignoreTimescale;
  10. private float m_LastRealTime;
  11. private void Start()
  12. {
  13. m_LastRealTime = Time.realtimeSinceStartup;
  14. }
  15. // Update is called once per frame
  16. private void Update()
  17. {
  18. float deltaTime = Time.deltaTime;
  19. if (ignoreTimescale)
  20. {
  21. deltaTime = (Time.realtimeSinceStartup - m_LastRealTime);
  22. m_LastRealTime = Time.realtimeSinceStartup;
  23. }
  24. transform.Translate(moveUnitsPerSecond.value*deltaTime, moveUnitsPerSecond.space);
  25. transform.Rotate(rotateDegreesPerSecond.value*deltaTime, moveUnitsPerSecond.space);
  26. }
  27. [Serializable]
  28. public class Vector3andSpace
  29. {
  30. public Vector3 value;
  31. public Space space = Space.Self;
  32. }
  33. }
  34. }