- Home /
Share data between scripts?
I want to create a scoring system. I have 4 buttons with 4 different but similar scripts and want to share 1 GUI Text for the scores. Example Code:
var something : Sprite;
var SpriteRenderer : SpriteRenderer;
var score : int = 0;
var guiScore : GUIText;
function OnMouseDown () {
if(SpriteRenderer.sprite == something) {
score += 1;
guiScore.text = "Score: " = score;
}
}
Right now, if I pressed a button and got a point then I pressed a different button the score would start from 0 again. How can I share data something like static variables but different scripts? I know this sounds a bit noobie but any help would be much appreciated. Thanks in advance
Answer by praveee · Aug 25, 2014 at 11:05 AM
Yeah, if you want to share data between scripts best way is to create static class and assign values
public static class MetaData
{
public static int Score;
}
// Access score by
MetaData.Score = 09;
Can you please do it in JavaScript because I don't really understand c# thanks
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
How to make it two seconds for Time.time? 2 Answers
Pause Menu background problem 0 Answers