2D Platformer, Rotate sprite/arm towards cursor not working [C]
I'm new to C# and Unity so I'm probably making a really simple mistake.
What I want to do is make my sprite/arm rotate towards my mouse, I've been following A LOT of tutorials, forum posts but NOTHING works. I've watched Brackey's "How to make a 2D Platformer Tutorial" and copied the code exactly. Some guy in the comment suggested using this:
void Update () { //rotation Vector3 mousePos = Input.mousePosition; mousePos.z = 5.23f; Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position); mousePos.x = mousePos.x - objectPos.x; mousePos.y = mousePos.y - objectPos.y; float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); } }
But nothing happens at all, it's like the game doesn't recognize my mouse, what am I doing wrong? I get no error messages/warning.
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612054421im_/https://answers.unity.com/themes/thub/images/avi.jpg)