so i have 2 scripts, one is map script, and one is the player script
Player script, the player have tag “Player”, has rigid body and capsule collider
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit) && PlayerGameObject.gameObject.tag == "Player")
{
isSelected = true;
Debug.Log("Player CLicked");
}
}
Map Script, the map consist of cubes that has cube collider and each one of the cube is tagged “Map”
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit) && gameObject.tag == "Map")
{
PlayerScript.isSelected = false;
Debug.Log("Map CLicked");
}
}
What i want to do is when i click the player, the isSelected become true, and when i click the map, the isSelected become false, what i got is when i click the map, the isSelected is true and the “Player CLicked” Log is shown up.
I tried to remove the raycast hit from both of the script to make it only check th tag, but the result i got nothing, no log shown up.