- Home /
The question is answered, right answer was accepted
Show Gui after amount of time
I want to show my GUI on spesific amount of time. I dont know why but it doesnt work. Is it because of NGUI? i also tried them as a gameobject, still doesnt work.
I spent 2 hours to find a similar question, i hope i didnt miss.
using UnityEngine;
using System.Collections;
[AddComponentMenu("NGUI/Interaction/Button Activate")]
public class showgui : MonoBehaviour
{
public GameObject target;
public bool show = false;
void Start()
{ if (target != null) NGUITools.SetActive(target, show); }
void update()
{
StartCoroutine ("showmenu");
}
IEnumerator showmenu(){
yield return new WaitForSeconds(3);
NGUITools.SetActive(target, show);
}
}
Sorry; "notworking" means; $$anonymous$$enu is not appearing. Doesn't show up anything.
Landern, Can you explain please more, I am really a kind of beginner.
if you mean something like this; unity gave me errorAssets/acm script/showgui.cs(17,33): error CS1502: The best overloaded method match for `UnityEngine.$$anonymous$$onoBehaviour.StartCoroutine(System.Collections.IEnumerator)' has some invalid arguments
using UnityEngine;
using System.Collections;
[AddComponent$$anonymous$$enu("NGUI/Interaction/Button Activate")]
public class showgui : $$anonymous$$onoBehaviour
{
public GameObject target;
public bool show = false;
void Start()
{ if (target != null) NGUITools.SetActive(target, show); }
void update()
{
StartCoroutine(showmenu);
}
IEnumerator showmenu(){
yield return new WaitForSeconds(3);
NGUITools.SetActive(target, show);
}
}
Answer by acmeydan · Feb 25, 2015 at 03:14 PM
ok, somehow I solved it. I copy this script to another gameobject and make target deactive at the beginning, after that it works.
Thank you for your help.
Answer by hexagonius · Feb 25, 2015 at 02:41 PM
First off, your update method needs to be upper case to be Unitys Update. But you wouldn't want to call the coroutine in Update anyways, instead call it in start.
Second, your string approach should work. For the second approach:
StartCoroutine(showmenu());
Thank you, it works now. But in wrong way; it appears, then after amount of time it disappears. It should be inverse. How can i make invisible in the begininng? I already wrote "public bool show= false"
using UnityEngine;
using System.Collections;
public class showgui : $$anonymous$$onoBehaviour
{
public GameObject target;
public bool show = false;
void Start()
{
StartCoroutine(showmenu());
}
IEnumerator showmenu(){
yield return new WaitForSeconds(5);
NGUITools.SetActive(target, show);
}
}
I don't know Ngui, but if that call to SetActive is the only way to deal with the menu and its default is visible you should call SetActive false prior to the coroutine call and SetActive true in the coroutine.
The string approach does work, but it comes with a heavier load for invocation then the literal method.
From the documentation:
In most cases you want to use the StartCoroutine variation above. However StartCoroutine using a string method name allows you to use StopCoroutine with a specific method name. The downside is that the string version has a higher runtime overhead to start the coroutine and you can pass only one parameter.
So unless you're using StopCoroutine...