How do I turn off the previous object?

I’m making a game in the td genre. I made it so that when the character clicks on the tower, the sprite turns on, which shows the range of action, but! if a person clicks on another tower, then the previous one will remain on, how can this be avoided? in all games of this genre, they make it so that if a person clicks on another tower or on the playing field, then the previous tower turns off. how to do it?

I do this on and off, i can’t figure out how to do it further

  public void OnMouseDown()
    {
        if(CyrcleUse.activeSelf == false)
        {
            CanvasTower.SetActive(true);
 
            CyrcleUse.SetActive(true);
        }
        else if (CyrcleUse.activeSelf == true)
 
        {
            CanvasTower.SetActive(false);
 
            CyrcleUse.SetActive(false);
        }
 
    }

Hi! in order to achieve this, you must save a reference to the last tower the player set on…

  1. Set active the tower,
  2. Store the current active tower on a variable (you can use the player script but if you want more complexity you should create a manager for towers)
  3. Player activates a new tower:
  4. The previous tower stored on the variable is set to inactive, the new tower is set to active, and then stored on the varialbe.

First time you do this you should chech with an if if theres a value on the tower variable, if not, just activate and store… if not, then activate and store…

i know im a bit late, hope this helps