trackCam.cs 723 B

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