Author Topic: How to adapt Scoreboard from OnGUI to NGUI?  (Read 2173 times)

Der_Kevin

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 10
    • View Profile
How to adapt Scoreboard from OnGUI to NGUI?
« 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

Der_Kevin

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: How to adapt Scoreboard from OnGUI to NGUI?
« Reply #1 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.  
« Last Edit: February 18, 2014, 03:34:25 AM by Der_Kevin »

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: How to adapt Scoreboard from OnGUI to NGUI?
« Reply #2 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;
« Last Edit: February 19, 2014, 09:12:15 AM by UncleAcid »