Hi all !
So i need some help to solve my problem
In my game, when i select a npc (i use Raycasting on a collider in a specific layer) a “popup” appear with his name and some others things (my next step is to design a dialog box with many choice).
To deselect, the player must click somewhere on the screen where there is nothing selectable (like WoW for example).
So i have that code, and it works properly :
if (Input.GetMouseButtonDown(0))
{
Ray ray = cameraPlayer.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//Selectable layer is 10
LayerMask layerMask = 1 << 10;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
//deselect the current selection
if (currentSelection != null)
{
currentSelection.SendMessageUpwards("DeSelected");
}
//tell to the hit object that he is selected
currentSelection = hit.collider.gameObject;
currentSelection.SendMessageUpwards("Selected");
}
else
{
//deselect the current selection
if (currentSelection != null)
{
currentSelection.SendMessageUpwards("DeSelected");
}
}
}
The problem is that, when i click on the “pop up” (some GUI elements), npc is deselect to.
What i want is to keep the selection active to be able to use button.
I suppose there is probably a solution with the layers but how specify a layer for GUI element ?
Thank you in advance