Author Topic: NGUI with HUD Text  (Read 2476 times)

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
NGUI with HUD Text
« on: March 14, 2014, 11:20:47 PM »
Hey guys,

So I got this NGUI button hidden, when I click this GameObject not part of the NGUI using something like this, I can get the button to appear, but I want it to appear on top of the GameObject I clicked... please I need help with this, I cant make it work so I bought HUD Text to get a help with it... btw here is the code.

  1. public class TowerSlot : MonoBehaviour
  2. {
  3.         public GameObject towerMenu = null;
  4.  
  5.        
  6.         void OnMouseDown()
  7.         {
  8.                 NGUITools.SetActive (towerMenu,true);
  9.         }
  10.  
  11. }
  12.  

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: NGUI with HUD Text
« Reply #1 on: March 14, 2014, 11:29:22 PM »
Update... I was using the UIFollowTarget script and it works on the first slot but it doesn't work when there are several of the same items on the game, it is a tower defense game and as you might guess, there are several of these spawning points for the towers. Any idea how to do it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI with HUD Text
« Reply #2 on: March 15, 2014, 05:53:31 PM »
OnMouseDown is a Unity event.

NGUI's equivalent is void OnPress (bool isPressed). Check the documentation page for UICamera.

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: NGUI with HUD Text
« Reply #3 on: March 15, 2014, 06:26:38 PM »
Hey ArenMook,

I can get the NGUI button to show with OnMouseDown() because the gameobject is not part of the GUI, what I cant make is make it appear on top of the clicked object, I want it appear on top of the gameobject I just clicked, right now it appears but its fixed on the position I created it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI with HUD Text
« Reply #4 on: March 15, 2014, 06:30:33 PM »
It doesn't matter if the object is a part of NGUI or not. It's still capable of receiving NGUI events -- as long as you have a UICamera script attached to the camera that draws it.

To make something in 2D UI appear on top of something in the 3D world, use math. Take its world position, use the camera to convert it to view coordinates. Then use the UI camera to convert it from screen back to world. Lastly use the transform of wherever you are placing it (like a panel) to convert the world coordinate into a local coordinate.

UIFollowTarget does this in HUDText, to give you an example.