Question by 
               Pancho_Cuadra · Oct 20, 2015 at 11:52 AM · 
                error message  
              
 
              Error when displaying score.
Greetings.
I'm working on a 2d hack-and-slash game and have a text object on a canvas to display score, the score is displayed correctly, but when I run the game within unity, I get the following error:
NullReferenceException: Object reference not set to an instance of an object KillCountScript.Update () (at Assets/Scripts/KillCountScript.cs:19)
The relevant code is here:
KillCountScript.cs:
using UnityEngine;
using UnityEngine.UI;
using System.Collections; 
public class KillCountScript : MonoBehaviour {
 public static Text KillsText;
 public static int KillCount;
 // Use this for initialization
 void Start () {
     KillsText = GetComponent <Text>();
     KillCount = 0;
 }
 
 // Update is called once per frame
 void Update () {
     KillsText = GetComponent <Text>();
     KillsText.text = "Kills: " + KillCount + " /100";
     if (KillCount == 100){
         Application.LoadLevel ("win scene");
     }
 }
 /*public static void UpdateKills (){
     KillsText = GetComponent <Text>();
     KillsText.text = "Kills: " + KillCount + " /100";
 }*/
 
               }
Thanks beforehand.
               Comment
              
 
               
              Your answer