I have a small problem; I’ve created an RTS and have done the whole fighting and moving as well as selection and was very successful. Now I wanted to implement that one can also disselect an soldier, so I wrote this simple thing:
if (Input.GetMouseButtonDown(1))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                if ((hit.transform.tag == "playerSoldier") && (selectionCounter == 0))
                {
                    soldier = hit.transform.gameObject;
                    selectedSolder = true;

                    selectionCounter = 1;
                }
                if ((hit.transform.tag == "playerSoldier") && (selectionCounter == 1))
                {
                    selectedSolder = false;
                    friendlyAIScript = null;
                    soldier = null;

                    selectionCounter = 0;
                }
            }
        }

But it isn’t working for some reason. The problem here is for me that I have like a blockade in my head. All conditions are met and it should be working in theory. But when I click onto the soldier with the right mouse button, nothing happens. I’m really confused. Might be a Burnout problem ;(

And moderators: I have a problem. I typed “Ray” ino the topic bar, also “Raycast” and many other things, but it tells me that nothing was found so I take this weird topic now. I feel like today is a weird day.

Line 8 - you are setting selectionCounter = 1 which makes the second if condition true (basically both if statements are true).

I suggest you change the third if to else if (line 10)