So i have a problem with player rotating to mouse and the problem is that it it doesnt work and spews out:
NullReferenceException: Object reference not set to an instance of an object
RotateToCursor.rotateToCamera () (at Assets/Scripts/RotateToCursor.cs:22)
RotateToCursor.Update () (at Assets/Scripts/RotateToCursor.cs:14)
Script:
Vector3 mousePos;
Rigidbody2D bod;
// Use this for initialization
void Start () {
bod = this.GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
rotateToCamera ();
}
void rotateToCamera()
{
mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Quaternion rot = Quaternion.LookRotation (transform.position - mousePos, Vector3.forward);
transform.rotation = rot;
transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
bod.angularVelocity = 0;
}
Thanks