Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

Why does my variable show a rising score AND 0 at the same time?

$
0
0
I'm making a score counter and letting other objects access it with Get and Set functions. The Inc(n) function works and "score" keeps going up, but GetString() shows "score" at 0. Why is that happening? #pragma strict private var score:int; function Start () { score = 0; } function Inc(a:int) { print("inc added "+a+" to score."); score = score+a; print("Score is now "+score+"."); } function GetString():String { print("Sending score as "+score); return score.ToString(); } function Get():int { return score; } function Set(a:int) { score = a; } Additional - here is a shortened version of the script that uses the Inc(n) function... #pragma strict // abridged code var scoreManager:ScoreManager; // This is so you can send stuff to the score manager. // abridged code function OnTriggerEnter(col:Collider) { for (a=0; a

Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>