I have a C# script that has a variable for the health of the player.
How can I access this variable from another C# script and displaa it as a GUIText??
like this---------
V
health: 2000
Thanks in advance!
I have a C# script that has a variable for the health of the player.
How can I access this variable from another C# script and displaa it as a GUIText??
like this---------
V
health: 2000
Thanks in advance!
In C#, if you declare a variable as static, you can reference said variable from any script. Example:
Script #1:
public class SetHealth : MonoBehaviour
{
public static float health = 2000;
void Start()
{
// Stuff
}
void Update()
{
// Stuff
}
}
Script #2:
public class GetHealth : MonoBehaviour
{
void Start()
{
// Stuff
}
void Update()
{
this.guiText.text = "Health: " + SetHealth.health;
}
}