I am making a tower defense game, and I want to have a circle that appears when you select an existing turret to show the range of it. To do this, I need to have the script on the circle access the range value that is held within the script on the turret. I would also like to be able to use this to upgrade turrets (so just changing values on the turret’s script during the game)
Use GetComponent to access the script.
Make sure the variable is public so you can access it from outside (as you are trying here)
Example:
GameObject turret; // The turret in question
float GetRange {
TurretScript turretScript = turret.GetComponent<TurretScript>();
return turretScript.range; // 'range' is the variable in TurretScript
}