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.

58 lines
1.2 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.Utility
  4. {
  5. public class CameraRefocus
  6. {
  7. public Camera Camera;
  8. public Vector3 Lookatpoint;
  9. public Transform Parent;
  10. private Vector3 m_OrigCameraPos;
  11. private bool m_Refocus;
  12. public CameraRefocus(Camera camera, Transform parent, Vector3 origCameraPos)
  13. {
  14. m_OrigCameraPos = origCameraPos;
  15. Camera = camera;
  16. Parent = parent;
  17. }
  18. public void ChangeCamera(Camera camera)
  19. {
  20. Camera = camera;
  21. }
  22. public void ChangeParent(Transform parent)
  23. {
  24. Parent = parent;
  25. }
  26. public void GetFocusPoint()
  27. {
  28. RaycastHit hitInfo;
  29. if (Physics.Raycast(Parent.transform.position + m_OrigCameraPos, Parent.transform.forward, out hitInfo,
  30. 100f))
  31. {
  32. Lookatpoint = hitInfo.point;
  33. m_Refocus = true;
  34. return;
  35. }
  36. m_Refocus = false;
  37. }
  38. public void SetFocusPoint()
  39. {
  40. if (m_Refocus)
  41. {
  42. Camera.transform.LookAt(Lookatpoint);
  43. }
  44. }
  45. }
  46. }