aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/ArmRotation.cs
blob: 95ea4594c1a4e7181211138b9d55f1d8701cb760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ArmRotation : MonoBehaviour
{
    [SerializeField]
    private float angle;
    private Vector2 slope;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            RotateToFacePoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        }
    }

    void RotateToFacePoint(Vector3 point)
    {
        slope = point - transform.position;
        slope.Normalize();
        angle = Mathf.Atan2(slope.y, slope.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
}