- Home /
Live system/Score, etc.
What is a script I can use to store data and then how would I display that data on the screen as numbers (I want to use it to make a score system,) also, how do I reference numerical values from other scripts (EX: Trigger A is activated and Value B in Script C increases by X)? Thank you.
Answer by denewbie · Nov 15, 2010 at 07:35 AM
Heres the script you need to display:
var myScore:int = 0; otherScript myScript;
function Start(){
myScript = GameObject.Find( AnotherGameObjectName ).GetComponent(otherScript); // "AnotherGameObjectName" is the name of the object containing the script and "otherScript" is the name of that script
}
function OnGUI(){
myScore = myScript.getScore(); // Where "getScore" is a function of that script
GUI.Label(Rect(0,0, 100, 30), "Score: " + myScore);
}
And heres a sample script called "otherScript.js"
var currentScore = 10;
function int getScore(){ return currentScore; }
Your answer
Follow this Question
Related Questions
Iphone gui text 2 Answers
Dynamically pass integer values into separate scripts in C#? 4 Answers
Display a number on the screen 2 Answers
C# How To Save PlayerPrefs for Unity GUI 2 Answers
Changing GUItext value 1 Answer