diff options
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/ArmRotation.cs | 32 | ||||
-rw-r--r-- | Assets/Scripts/ArmRotation.cs.meta | 11 |
2 files changed, 43 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); + } +} diff --git a/Assets/Scripts/ArmRotation.cs.meta b/Assets/Scripts/ArmRotation.cs.meta new file mode 100644 index 0000000..0a78e03 --- /dev/null +++ b/Assets/Scripts/ArmRotation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 315ad107404f29a4fb83b71c32b992d0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |