Author Topic: NGUI: HUD Text  (Read 192789 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #240 on: September 29, 2016, 04:22:08 AM »
Just write a script to do that. In Update() check the distance, if close enough, enable target game object. If too far, disable target game object. This has nothing to do with HUDText.

samshosho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Very strange behaviour on Android! please help
« Reply #241 on: October 08, 2016, 08:49:30 AM »
This is a very strange problem i came across today.
Porting one of my IOS games to Android.
It works flawlessly in the Editor and for IOS, however building for Android device resulted in very strange behaviour!!!

The sprites that suppose to update their position according to where the player is and the target position, just don't update their position! first update cycle is done and then they just stop and sometimes disappear!

i did a debug print out to see if the position is changed when the player moves, and it updates once, then stops.

The editor is working just fine with no problem, also building for IOS has no problem. The sprits move and change their position every frame.

Basically this script is suppose to show an indication onscreen to where the next target is according the position of the player and the way he is facing.
If the indication sprite goes off screen, it keeps it inside the screen at the screen's corners.

  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5.  
  6. /// <summary>
  7. /// Example script showing how to add UI window that follows an object drawn by another camera.
  8. /// </summary>
  9.  
  10. [AddComponentMenu("NGUI/Examples/Unit HUD")]
  11. public class UnitHUD : MonoBehaviour
  12. {
  13.     /// <summary>
  14.     /// Target object this UI element should follow.
  15.     /// </summary>
  16.  
  17.     public Transform target;
  18.  
  19.     Transform mTrans;
  20.     Camera mGameCam;
  21.     Camera mUICam;
  22.     Vector3 mPos;
  23.     bool mVisible = true;
  24.     public float YAdjustFactor = 2f;
  25.     public Transform Player;
  26.     private UIWidget MyWidget;
  27.  
  28.     public bool ChangeColor;
  29.  
  30.     void Start ()
  31.     {
  32.         mTrans = transform;
  33.         //target = mTrans;
  34.         if (target == null) { Destroy(gameObject);
  35.  
  36.             return; }
  37.  
  38.         mGameCam = NGUITools.FindCameraForLayer(target.gameObject.layer);
  39.         mUICam = NGUITools.FindCameraForLayer(gameObject.layer);
  40.         MyWidget = gameObject.GetComponentInChildren<UIWidget>();
  41.     }
  42.  
  43.     void LateUpdate()
  44.     {
  45.         if (target == null) { Destroy(gameObject); return; }
  46.         if (!target.gameObject.activeInHierarchy) {gameObject.SetActive(false); return;}
  47.         Vector3 screenpos = Camera.main.WorldToScreenPoint(target.position);
  48.        
  49.  
  50.         mPos = mGameCam.WorldToViewportPoint(target.position);
  51.  
  52.         bool visible = (mPos.z > 0f && mPos.x > 0f && mPos.x < 1f && mPos.y > 0f && mPos.y < 1f);
  53.      
  54.         if (visible){
  55.             mTrans.localPosition = screenpos;
  56.             MyWidget.enabled = false;
  57.         }
  58.         else {
  59.          
  60.             if (mPos.z < 0)
  61.                 mPos *= -1;
  62.             //print("mpos = "+mPos);
  63.             MyWidget.enabled = true;
  64.             mPos.x = Mathf.Clamp01(mPos.x);
  65.             mPos.y = Mathf.Clamp01(mPos.y);
  66.             //print("mpos Clamped = "+mPos);
  67.  
  68.             if(mPos.x > 0.95f)
  69.                 mPos.x = 0.95f;
  70.          
  71.             if(mPos.y > 0.95f)
  72.                 mPos.y = 0.95f;
  73.          
  74.  
  75.             if(mPos.x < 0.05f)
  76.                 mPos.x = 0.05f;
  77.          
  78.             if(mPos.y < 0.05f)
  79.                 mPos.y = 0.05f;
  80.          
  81.          
  82.             mPos = mUICam.ViewportToWorldPoint(mPos);
  83.             mPos = MyWidget.transform.parent.InverseTransformPoint(mPos);
  84.             mPos.z = 0;
  85.             MyWidget.transform.localPosition = mPos;
  86.         }
  87.     }
  88. }
  89.  

samshosho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI: HUD Text
« Reply #242 on: October 09, 2016, 06:55:01 AM »
I have done all i can and tried so many different things and rebuilt 100 times, but nothing helped.
Can someone from NGUI creators answer this please.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #243 on: October 11, 2016, 10:59:38 AM »
First guess -- turn off the multi-threaded rendering option for Android.

samshosho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI: HUD Text
« Reply #244 on: October 11, 2016, 11:02:49 AM »
Not using it already!

The game is ready to be published on the Google Play, however this is the only thing that's holding it back.
What else could cause that?

note that other strange behaviour is occurring in another game, but it's not essential to the game as the one at hand. This game at hand, i have to have these Sprite indicators to show next targets.

However in the other games, it's mostly health bar, which i removed as it's not so essential to the game, until i find a solution.

gearedgeek

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: NGUI: HUD Text
« Reply #245 on: February 06, 2017, 06:55:18 PM »
I'm looking to add this to my project and I need help trying to get it working with the AI health. I would like to use playmaker if possible.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #246 on: February 08, 2017, 09:00:57 AM »
I don't know either of those two extensions, so can't be of much help. HUDText is ridiculously simple to use via code though. The readme explains the few steps involved.