Is it possible to access a script in one duplicated game objets.

I have 8 towers in my game all with a script attached called “Tower”, I want to access a variable in the script “Towers” in only ONE of the eight towers (selected by the player) from “GameManager” script, I tried creating a Game Object in the script “Towers” to store the selected tower in it (because the selection function exists in “Towers”) then access it (the selected tower) and access the “Towers” script it contains, but it dosen’t seem to work, any ideas?

using UnityEngine;

public class Towers : MonoBehaviour {
    
    public int NrOfUnits ;
    public GameObject BaseTower; //the var that the GameManager will access
          
    // Use this for initialization
    void Start()
    {
      
    }



    // Update is called once per frame
    void OnMouseDown()
    {   
             //accessing the game manager
            GameObject theGameManager = GameObject.Find("GameManager");
            TheGameManager SelectionScript = theGameManager.GetComponent<TheGameManager>();
          
            //if no tower is selected, the selected one will be the base tower
            if (SelectionScript.isTarget == false)
            {
                SelectionScript.selectedBaseTower = gameObject;
                SelectionScript.Position = this.gameObject.transform.position;
                SelectionScript.isTarget = true;
               //affecting the selected tower to the var
                BaseTower = gameObject;
            }
            //if a tower is already selected, the second selection will be the target tower
            else 
            {
            if (this.gameObject != SelectionScript.selectedBaseTower)
            {  
                SelectionScript.selectedTargetTower = gameObject;
                              
                SelectionScript.Move = true;
            }
            else
            {
                SelectionScript.selectedBaseTower = null;
                SelectionScript.selectedTargetTower = null;                                               
                SelectionScript.isTarget = false;
                SelectionScript.Move = false;
                BaseTower = null;
            }                 
            }
    }
}

and this is the GameManager

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TheGameManager : MonoBehaviour
{
    public GameObject selectedBaseTower;
    public GameObject selectedTargetTower;
    public bool isTarget = false;
    public Vector3 Position;

    public GameObject[] units;
    public GameObject[] unitsInst;
    public Vector3 spawnValues;
    public float spawnWait;
    public float spawnMostWait;
    public float spawnLeastWait;
    public int startWait;
    public bool stop;
    int randEnemy;

    public bool Move = false;
    // Use this for initialization
    void Start()
    {   
        StartCoroutine(waitSpawner());
        unitsInst = new GameObject[units.Length];
        
        for (int i =0; i < units.Length; i++)
        {
            unitsInst _= Instantiate(units*);*_

unitsInst*.SetActive(false);*
unitsInst*.transform.Translate(Position.x,Position.y,Position.z);*

}
}

// Update is called once per frame
void Update()
{
//spawnWait = Random.Range(spawnLeastWait, spawnMostWait);
if(Move == true)
{
for (int i = 0; i < unitsInst.Length; i++)
{

unitsInst*.SetActive(true);*
}
}
//selectedBaseTower = null;
//selectedTargetTower = null;
}

IEnumerator waitSpawner()
{
if (Move==true)

randEnemy = Random.Range(0, unitsInst.Length);
//Vector3 spawnPosition = new Vector3(selectedBaseTower.transform.position.x, selectedBaseTower.transform.position.y, selectedBaseTower.transform.position.z);
Instantiate(unitsInst[randEnemy], Position , unitsInst[randEnemy].transform.rotation);
// accessing selected tower

//I know thiswon’t work, static didn’t either and I couldn’t figure it out
GameObject temp = Towers.BaseTower;
Towers TempTower = temp.GetComponent();
TempTower.BaseTower…

yield return new WaitForSeconds(1);

}

}
Now to explain more, what I mainly want to do, is when a player selects a base and target tower, the gameManager reduces the NrOfUnits in the base tower.
@JVene

Hello,

Did you try to acces uniq ID of the GameObject, which is your selected tower?

You can learn more about the uniq ID in the link below.