EDIT: RESOLVED
Yes this has been asked a number of times, and I’m sorry but I’m out of idea’s
I have been working through the 3d survival tutorial (but working with my own assets).
For the life of me I can not get my player model to move on a mouse click. With the original PlayerMovement script, my player would rotate to face the mouse. So I know at least the mouse x/y is detected via rayCast.
I also was able to set it to mouse movement and testing would adjust my model depending on if I moved my mouse up/down left/right etc.
The tutorials code i’ve tried:
// Update is called once per frame
void Update ()
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Input.GetButtonDown ("Fire2"))
{
if (Physics.Raycast(ray, out hit, 100))
{
if (hit.collider.CompareTag("Enemy"))
{
targetedEnemy = hit.transform;
enemyClicked = true;
}
else
{
walking = true;
enemyClicked = false;
navMeshAgent.destination = hit.point;
navMeshAgent.Resume();
}
}
}
No dice. Since then I have reset the Input Manager, ensured “mouse 0” “mouse 1” “mouse 2” are assigned under “Fire 1-3”. No Dice.
I have since put some debug lines at the start of void Update (). And have hard coded the mouse 0 press.
Debug log while playing accurately reflects the changes of my mouses cursor position. but always reports that my mouse 0 button is not pressed. I should note that I pressed (and released) and held all mouse buttons on my mouse to get it to report a press (in case “mouse 0” in unity is not my left mouse button".
// Update is called once per frame
void Update ()
{
Debug.Log(Input.mousePosition.ToString());
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Pressed left click.");
}
else
{
Debug.Log("Not Clicked Mouse LEFT");
}
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit, 100))
{
if (hit.collider.CompareTag("Enemy"))
{
targetedEnemy = hit.transform;
enemyClicked = true;
}
else
{
walking = true;
enemyClicked = false;
navMeshAgent.destination = hit.point;
navMeshAgent.Resume();
}
All I can get back is:
(930.0, 960.0, 0.0)
UnityEngine.Debug:Log(Object)
CompleteProject.ClickToMove:Update() (at Assets/Scripts/ClickToMove.cs:45)
Not Clicked Mouse LEFT
UnityEngine.Debug:Log(Object)
CompleteProject.ClickToMove:Update() (at Assets/Scripts/ClickToMove.cs:52)
Any ideas? Lastly my mouse is not a generic no name, it’s a Wired USB Mad Cat Z Rat 4.