Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Der_Kevin on February 17, 2014, 04:13:13 PM

Title: How to adapt Scoreboard from OnGUI to NGUI?
Post by: Der_Kevin on February 17, 2014, 04:13:13 PM
Hey. Iam just trying to adapt my old Unity GUI to NGUI and have somehow no clue how to display the cash amount of my game. with Unity GUI i do it like this:

  1. GUI.Label(new Rect(startPosTop.x + 80.0f, startPosTop.y - 25.0f, 100.0f, 30.0f), "CASH: " + m_spawnController.m_playerCash);
  2.                

can somebody tell me how i do this in NGUI?

Cheers,
Kev
Title: Re: How to adapt Scoreboard from OnGUI to NGUI?
Post by: Der_Kevin on February 18, 2014, 03:19:51 AM
ok. i tried to figure it out on my own. it looks like this now:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CashView : MonoBehaviour {
  5.        
  6.         public UILabel resourceLabel;
  7.         //private int displayedResources;
  8.  
  9.         private SpawnController m_spawnController                       = null;
  10.        
  11.         void Awake()
  12.         {
  13.                 m_spawnController = GameObject.FindWithTag("SpawnController").GetComponent<SpawnController>();
  14.         }
  15.        
  16.         public void UpdateResource(bool instant = false) {
  17.                 resourceLabel.text = "CASH: " + m_spawnController.m_playerCashh();
  18.                 }
  19.  
  20. }
  21.  
  22.  

but i get the error:
CashView.cs(17,64): error CS1955: The member `SpawnController.m_playerCash' cannot be used as method or delegate

btw here is the full old script:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CashViewOld : MonoBehaviour
  5. {
  6.                
  7.         private SpawnController m_spawnController                       = null;
  8.        
  9.         void Awake()
  10.         {
  11.                 m_spawnController = GameObject.FindWithTag("SpawnController").GetComponent<SpawnController>();
  12.                
  13.         }
  14.  
  15.  
  16.         void OnGUI()
  17.         {
  18.                 Vector2 buttonSize = new Vector2(120, 40);
  19.                 Rect startPosTop = new Rect(90, 30, buttonSize.x, buttonSize.y);
  20.  
  21.                 GUI.Label(new Rect(startPosTop.x + 80.0f, startPosTop.y - 25.0f, 100.0f, 30.0f), "CASH: " + m_spawnController.m_playerCash);
  22.         }
  23. }
  24.  
Title: Re: How to adapt Scoreboard from OnGUI to NGUI?
Post by: UncleAcid on February 18, 2014, 10:05:10 AM
Based on your old code; m_playerCash is a property/public variable, not a method. So just remove the brackets.

  1. resourceLabel.text = "CASH: " + m_spawnController.m_playerCashh();
becomes
  1. resourceLabel.text = "CASH: " + m_spawnController.m_playerCash;