- Home /
Mouse input not being recognised
Out of nowhere, my rts camera stopped recognising certain mouse actions. I can't select units anymore, and trying to place building pieces messes up because their transform isn't getting set to the mouse position anymore. When I try to select a unit, it only registers the terrain and nothing else. I am still able to click on trees and rocks and they get recognised, but that's it....
well, how you pickup the inputs, the "units" have colliders? de device is a standard mouse? please provide more info...
Yes, the units have a navmeshagent and a box collider attached. It is just a standard mouse. Here is the code used:
//Detect if mouse is down
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
mousePositon = Input.mousePosition;
//Create a ray from the camera to our space
var camRay = rtsCam.ScreenPointToRay(Input.mousePosition);
//Shoot that ray and get the hit data
if (Physics.Raycast(camRay, out hit))
{
Debug.Log(hit.transform);
if (hit.transform.CompareTag("PlayerUnit"))
{
print("player unit found");
SelectUnit(hit.transform.GetComponent<UnitController>(), Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift));
}
else
{
isDragging = true;
}
}
}
Do you get any errors?
What is the debug output? And does it ever match what you believe you are clicking on?
You'll need to share your code and explain how it currently selects, whether you have any errors and what you have tried so far.
//Detect if mouse is down
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
mousePositon = Input.mousePosition;
//Create a ray from the camera to our space
var camRay = rtsCam.ScreenPointToRay(Input.mousePosition);
//Shoot that ray and get the hit data
if (Physics.Raycast(camRay, out hit))
{
Debug.Log(hit.transform);
if (hit.transform.CompareTag("PlayerUnit"))
{
print("player unit found");
SelectUnit(hit.transform.GetComponent<UnitController>(), Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift));
}
else
{
isDragging = true;
}
}
}
There are no errors, just simply nothing happening. The unit has a box collider and navmeshagent, I don't know if those conflict with eachother but I haven't had problems yet.
Your answer
![](https://koobas.hobune.stream/wayback/20220612200455im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Examples of TBS/Heavily Gui-driven Games in Unity? 2 Answers
3D mouse position 0 Answers
Ray Over Mouse 1 Answer
How I can save mouse position ? 0 Answers
How to prevent GameObject from spawning on top of each other? 1 Answer