Advertisement
crystalguy123

Untitled

Jan 30th, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Weapon : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10.  
  11. }
  12.  
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
  17. float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
  18. Quaternion rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
  19. transform.rotation = rotation;
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement