Hi all, I have started to use Unity this year and I try to make a 2D top view game.
In this game the player have 16 sprites (frames). So what Im looking for is to change the sprite to the correct one depending of where the mouse clicks (angle in 360 degrees relative to player position). Something like a compass.

Example: If the mouse click in 90 degrees, change to the sprite which face up.
The question is: How to get this angle?
I tried much thinks but dont seems to be what im looking for. Hope you can help me.
Thank’s in advance.
Here is some code that implements three different ways to find that angle. Note way #1 and way #2 assume the camera is looking along the Z axis. If you are doing a top view by looking down the Y axis, you will need to make the appropriate changes. Take this script and attach it to an empty game object. Drag an object into the scene for goPlayer.
public class FindAngle : MonoBehaviour {
public GameObject goPlayer;
void Update() {
Vector3 v3Pos;
float fAngle;
if (Input.GetMouseButtonDown(0)) {
// Project the mouse point into world space at
// at the distance of the player.
v3Pos = Input.mousePosition;
v3Pos.z = (goPlayer.transform.position.z - Camera.main.transform.position.z);
v3Pos = Camera.main.ScreenToWorldPoint(v3Pos);
v3Pos = v3Pos - goPlayer.transform.position;
fAngle = Mathf.Atan2 (v3Pos.y, v3Pos.x) * Mathf.Rad2Deg;
if (fAngle < 0.0f) fAngle += 360.0f;
Debug.Log ("1) "+fAngle);
// Raycast against a mathematical plane in world space
Plane plane = new Plane(Vector3.forward, goPlayer.transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float fDist;
plane.Raycast(ray, out fDist);
v3Pos = ray.GetPoint (fDist);
v3Pos = v3Pos - goPlayer.transform.position;
fAngle = Mathf.Atan2 (v3Pos.y, v3Pos.x) * Mathf.Rad2Deg;
if (fAngle < 0.0f) fAngle += 360.0f;
Debug.Log ("2) "+fAngle);
//Convert the player to Screen coordinates
v3Pos = Camera.main.WorldToScreenPoint(goPlayer.transform.position);
v3Pos = Input.mousePosition - v3Pos;
fAngle = Mathf.Atan2 (v3Pos.y, v3Pos.x)* Mathf.Rad2Deg;
if (fAngle < 0.0f) fAngle += 360.0f;
Debug.Log ("3) "+fAngle);
}
}
}