Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: GantZ_Yaka on May 07, 2013, 10:20:57 PM

Title: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
Post by: GantZ_Yaka on May 07, 2013, 10:20:57 PM
Why this code doesnt work?
  1. using UnityEngine;
  2. using System.Collections;
  3. public class AreaScript : MonoBehaviour {
  4. public GameObject uiObject;            
  5. void Start () {
  6. uiObject = GameObject.Find("PanelTrigger1");   
  7. NGUITools.SetActive(uiObject,false);
  8.         }
  9.     void OnTriggerEnter(Collider other)
  10.     {
  11.         NGUITools.SetActive(uiObject,true);
  12.         }
  13.         void OnTriggerExit(Collider other)
  14.     {
  15.         NGUITools.SetActive(uiObject,false);
  16.     }  
  17. }
  18.  

Why its hard to find NGUI-tutorial of such an important thing as hiding/showing panels during entering the trigger?
Title: Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
Post by: ArenMook on May 08, 2013, 02:13:56 AM
Because you can't destroy objects from within a physics callback such as OnTrigger. Set a variable instead such s "hasbeenDestroyed = true", and check for it in the Update function.
Title: Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
Post by: hazzius on April 26, 2014, 06:12:55 PM
What i must to do for enable HUD objects then i pass EnablerTriggerZone and disable HUD objects then i pass DisablerTriggerZone ?

Attach not working EnablerTriggerZone script. All Debug is fine, i see it all in console in time.
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class s_BlueTrigger : MonoBehaviour {
  5.         private GameObject Blue;
  6.         public bool BlueTrigger = false;
  7.  
  8.         void Start ()
  9.         {
  10.                 Blue = GameObject.FindGameObjectWithTag("4_Blue");
  11.                 Debug.Log("Blue Detected");
  12.         }
  13.  
  14.         void Update ()
  15.         {
  16.                 if (BlueTrigger)
  17.                 {
  18.                         NGUITools.SetActive (Blue, true);
  19.                         Debug.Log("Blue True");
  20.                 }
  21.         }
  22.  
  23.         void OnTriggerEnter (Collider Other)
  24.         {              
  25.                 if (Other.gameObject.tag == "Player")
  26.                 {
  27.                         BlueTrigger = true;
  28.                         Debug.Log("Blue Triggered");
  29.                 }
  30.         }
  31. }              


Why this not work? I newbie in C# Unity and NGUI. Plz make some big answer.
And tell me, why i cant use grid in realtime? It put objects in grid and sort them only at start. If i turn off and on components at Play Mode, the components not automatically sorted in grid, just activated in places there been disabled?

Sry for bad English.
Title: Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
Post by: Sahkan on April 27, 2014, 11:20:41 AM
Why don't you use Renderer.enabled = true/fales on this object ?
Title: Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
Post by: ArenMook on April 27, 2014, 11:55:15 PM
I already explained why this is not possible, hazzius:
Because you can't destroy objects from within a physics callback such as OnTrigger. Set a variable instead such s "hasbeenDestroyed = true", and check for it in the Update function.
This is just how Unity works. You cannot destroy things inside a physics callback. OnTrigger is a physics callback.