Hi,
I have a character(only runs forward), holding a gun looking at mouseposition, while looking forward everything is okay. but while looking back it doesn’t look at mouse cursor.
Here is my codes
Cursor Script;
using UnityEngine;
using System.Collections;
public class Cursor : MonoBehaviour {
void Update () {
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
transform.position = new Vector3 (pos.x, pos.y, 0);
}
}
And Follow Mouse Script:
using UnityEngine;
using System.Collections;
public class FollowMouse : MonoBehaviour {
public Transform cursor;
public float number; //Number to Divide angle for Weapon and Head;
public bool facingRight=true;
void Update () {
Vector3 dir= cursor.position - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle/number, Vector3.forward);
}
void Flip(){
facingRight=!facingRight;
Vector3 theScale=transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
I Want to Use Flip Method But it doesn’t work, please help someone.
Thank You…