Question by
alvola · Dec 15, 2015 at 07:43 PM ·
c#nullreferenceexceptionontriggerenterscore system
NullReferenceException: Object reference not set to an instance of an object
I want to update my score!!
This is the ScoreHandler class: public int score = 0; public int scorePrincipalObject = 10; public int scoreCoin = 1;
public Text scoreText;
// Update is called once per frame
void Update () {
scoreText.text = "Score: " + score;
}
and this is the class in the object:
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag.Equals("Player"))
{
Debug.Log("Picked"); // received
scoreHandler.score += scoreHandler.scorePrincipalObject;
Destroy(transform.parent.gameObject);
}
}
Thanks!
Comment