Author Topic: Updating Labels Through Script - Null Errors - SOLVED  (Read 2476 times)

SeaCliffInteractive

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Updating Labels Through Script - Null Errors - SOLVED
« on: April 10, 2014, 12:36:29 PM »
Hey all,

I'm somewhat new to NGUI and I'm having trouble updating the text of an existing label with a variable through script. I'm building a unit purchase menu and want to display how many units are currently owned. This variable is housed in a different script and I can't seem to access due to some null errors. Lines 14 and 40 are the ones receiving the errors.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PurchaseManager : MonoBehaviour
  5. {
  6.  
  7.         public UILabel countLabel;
  8.         internal string countLabelString;
  9.  
  10.  
  11.         void Start ()
  12.         {
  13.                 countLabel.text = "hello";
  14.  
  15.         }
  16.        
  17.  
  18.         public void PurchaseAuxilia() // Buy an Auxilia
  19.         {
  20.                 if (WorldMapManager.stockedGold >= 50)
  21.                 {
  22.                         WorldMapManager.stockedGold -= 50;
  23.                         WorldMapManager.AuxiliaUnits += 1;
  24.                         countLabelString = WorldMapManager.AuxiliaUnits.ToString();
  25.                         countLabel.text = "countLabelString";
  26.                 }
  27.  
  28.         }

Thanks in advance!
« Last Edit: April 10, 2014, 01:03:09 PM by SeaCliffInteractive »