Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerAiming : MonoBehaviour
- {
- public Rigidbody2D rbGun;
- public Camera cam;
- Vector2 mousePos;
- void Start()
- {
- }
- void Update()
- {
- Aim();
- }
- public void Aim()
- {
- mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
- Vector2 lookDir = mousePos - rbGun.position;
- float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
- rbGun.rotation = angle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement