- Home /
 
Help with GUIText health bar please
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! :)
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Chifilly · Nov 12, 2012 at 04:58 PM
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;
     }
 
 }
 
              Your answer
 
             Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Inventory Cursor Location 1 Answer
Multiple Cars not working 1 Answer
gui label works in js but not in cs 1 Answer
Hi! How do I make a text that changes with the behind picture? 0 Answers