Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

accessing a variable from another script.

$
0
0
I am very new to programming and struggling with a problem. I am trying to access the variable "score" from one script and use "score" to determine the height of a guitexture on another script. I have tried it a couple ways but i keep getting this error: Null Reference Exception: Object reference not set to an instance of an object. This is how my script is written. //this is my first script, which is named: stonyScript var score : float = 0; function OnCollisionEnter(col : Collision){ if(col.gameObject.name == ("asteroid")){ score += 10; } //here is the second script. currentHeight = stonyScript.js.score; function Update(){ guiTexture.pixelInset.width = 20; guiTexture.pixelInset.height = 10 + currentHeight; }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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