onclick event between tags

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.

I realized what seems to be the problem, when the mouse clicked, the script does not check whether the the object it’s clicked is with the tag “Player” or “Map”, rather it just checking whether the tag “Map” and “Player” exist, in this case it always true

So i decide to change the script
For the player script i remove the Input.GetMouseButtonDown(0) and change it to

void OnMouseDown()
    {
        if (PlayerGameObject.tag == "Player")
        {
            isSelected = true;
            Debug.Log("Player Clicked");
        }
    }

and for the map script, i decide not to put the event there, and instead i create a script for each cube that created

The Cube script

void OnMouseUp()
    {
        Debug.Log("Map Click");
        PlayerScript.isSelected = false;
    }

Therefore if i click the player the log will show “Player Clicked” and isSelected = true, and when i click the map (that consist of many cubes) i will get “Map Click” and isSelected = false.

Hope these help.