SFX_LookAtMouse.cs 634 B

1234567891011121314151617181920212223
  1. using UnityEngine;
  2. // ReSharper disable once CheckNamespace
  3. namespace QFX.SFX
  4. {
  5. public class SFX_LookAtMouse : MonoBehaviour
  6. {
  7. public float RotationSpeed;
  8. private void FixedUpdate()
  9. {
  10. var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  11. RaycastHit hit;
  12. if (!Physics.Raycast(ray, out hit))
  13. return;
  14. var targetRotation = Quaternion.LookRotation(hit.point - transform.position);
  15. transform.rotation =
  16. Quaternion.Lerp(transform.rotation, targetRotation, RotationSpeed * Time.deltaTime);
  17. }
  18. }
  19. }