Can't retrieve string value

Hey!
I am working on a target/select script for my towerdefence game. When I click a tower for example I want to be able to read stats from that tower, such as health and armor. Atm I am trying to access the name from this object aswell but I just can’t retrieve it.

				if(hitTower.collider.tag == "MiniTower"){
				targetClicked = true;
				mainTowerClicked = false;
				enemyClicked = false;
				//showHealth : MiniTowerHP;
				showStats = hitTower.collider.gameObject.GetComponent(MiniTowerHP);
				getHealth = showStats.currentHealth;				
				getMaxHealth = showStats.healthTower;				
				getArmor = showStats.armor;				
				retriewName = showStats.name; //here is where the error comes
				
				//showHealth = hitTower.collider.gameObject.MiniTowerHP.currentHealth;
				
				
				}

And it’s trying to access this String, which is in another script:

public var name : String;

Thanks in advance!

“Tried both of ur solutions but still get error at that line :frowning: Ambiguous reference ‘name’: MiniTowerHP.name, UnityEngine.Object.name.”

You should have started with this. Your problem is that your object already has a name members from MonoBehaviour and you are hiding it with a new implemtation.
Try to use a different variable name for your name like Name or towerName.

you could make a script on each tower like:
OnMouseOver(){
gamemaster.SendMessage(“GiveStats”, health, armor, killcount /etc…/)
}

the giveStats function would then be called and in there you could transfer these variables to a e.g healthToDisplay variable.
than you could make a guibox with the healthToDisplay variable.

note: my syntax isn’t correct but the idea of sendmessage and arguments is still valid.
:slight_smile: