- Home /
¿Score system with the new UI?
Hello there, I'm trying to do is: When the player colliding with the GOLD COIN, add 150 points to a text of the new UI and displayed on the screen. I saw that this could be done in a tutorial Unity video official, but as I did not understand, and I get an error. GOLD COIN to collide with the player, this object(gold coin)gets the variable SCORE of a script that has the text canvas and there adds 150 points. But this goes to collide with an error. "NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator ".
How do I fix this? Sorry, I use google translator, thank you very much.
Part of the script: GOLD COIN
var hudscore : GameObject;
function Awake(){
hudscore = GameObject.Find("ScoreNumero");
hudscore.GetComponent(Puntajes);
}
function OnTriggerEnter (collision : Collider) {
if(collision.gameObject.CompareTag("Player")&& posible == 1){
sumarpuntaje();
}
}
function sumarpuntaje(){
hudscore.score += 150;
Destroy (gameObject);
}
Text CANVAS
import UnityEngine;
import UnityEngine.UI;
var Texto : Text;
public var score : int;
function Awake(){
Texto.GetComponent(Text);
}
function Update(){
Texto.text = "Score : " + score;
}
Your answer
Follow this Question
Related Questions
How do I get a component of canvas? 0 Answers
¿Score system with the new UI? 0 Answers
I need help making my score not reset on Awake, but on a scene i have 0 Answers
getting a float value from another script 1 Answer
Scoresystem wont function correctly 0 Answers