Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerAiming : MonoBehaviour
  6. {
  7. public Rigidbody2D rbGun;
  8.  
  9. public Camera cam;
  10.  
  11. Vector2 mousePos;
  12.  
  13. void Start()
  14. {
  15.  
  16. }
  17.  
  18. void Update()
  19. {
  20. Aim();
  21. }
  22.  
  23. public void Aim()
  24. {
  25. mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
  26.  
  27. Vector2 lookDir = mousePos - rbGun.position;
  28.  
  29. float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
  30. rbGun.rotation = angle;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement