Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 25, 2015 at 03:17 PM by Landern for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by acmeydan · Feb 25, 2015 at 02:20 PM · guiwaitforsecondssetactive

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);
           }
  }
 
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image acmeydan · Feb 25, 2015 at 02:31 PM 0
Share

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);
           }
  }
 
avatar image El Maxo · Feb 25, 2015 at 02:33 PM 0
Share

what versions of unity are you on?

2 Replies

  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

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());
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image acmeydan · Feb 25, 2015 at 02:52 PM 0
Share

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);
           }
  }
 
avatar image hexagonius · Feb 25, 2015 at 03:13 PM 0
Share

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.

avatar image Landern · Feb 25, 2015 at 03:17 PM 0
Share

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...

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Both IF statements in a function are run and their conditions are ignored. 4 Answers

yield WaitForSeconds makes GUI button disappear 1 Answer

Why isn't my simple coroutine working? (and how can I make it infinite?) 2 Answers

Help with citizen conversation script. 1 Answer

I have a button with a cooldown. How do I make it so the cooldown time increases with each press of the button? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges