diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-04-18 13:22:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-18 13:22:11 -0500 |
commit | 41e8678c463b7606dfaf292d67d05244ff044878 (patch) | |
tree | 4bad1628cc223bbd40bd5a593c8bf9576fda0402 /Assets/Scripts/ArmRotation.cs | |
parent | a8e4db0544c6b2ac370693ad32e0e4adc01ef32e (diff) | |
parent | b11db6ce1af50c7f76f17b3797c76275f81801d2 (diff) |
Merge pull request #6 from MontanaJohns/develop
Prototype
Diffstat (limited to 'Assets/Scripts/ArmRotation.cs')
-rw-r--r-- | Assets/Scripts/ArmRotation.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Assets/Scripts/ArmRotation.cs b/Assets/Scripts/ArmRotation.cs new file mode 100644 index 0000000..95ea459 --- /dev/null +++ b/Assets/Scripts/ArmRotation.cs @@ -0,0 +1,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); + } +} |