2
0

trackObj.cs 749 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace Valve.VR.InteractionSystem.Sample
  4. {
  5. public class trackObj : MonoBehaviour
  6. {
  7. public Transform target;
  8. public float speed;
  9. public bool negative;
  10. private void Update()
  11. {
  12. Vector3 look = target.position - transform.position;
  13. if (negative)
  14. {
  15. look = -look;
  16. }
  17. if (speed == 0)
  18. {
  19. transform.rotation = Quaternion.LookRotation(look);
  20. }
  21. else
  22. {
  23. transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(look), speed * Time.deltaTime);
  24. }
  25. }
  26. }
  27. }