Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by LoKo6264 · May 21, 2016 at 09:29 PM · main menuendback

Back to main menu after 3s from show ui text

Hi, I made game with collectibles and after collect all of them on the screen we can see "you won" which is UI Text. I'd like to back to main menu after 3 seconds from this text. This UI Text is including all game scene. In my build settings main menu has number 2 - for easier make code for me. How then can I do it, with script I guess?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by corn · May 22, 2016 at 07:15 AM

Easiest way to do it would be to attach a script to your text, and only activate your text's GameObject when you show it, so that you can call the code to load the scene with the OnEnable callback. To wait for 3s, you need to use a Coroutine.

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Collections;
 
 public class LoadScene : MonoBehaviour
 {
     [SerializeField]
     private int m_SceneIndex = 2;
 
     [SerializeField]
     private float m_DelayBeforeLoad = 3f;
 
     private void OnEnable()
     {
         StartCoroutine(WaitAndLoadScene(m_SceneIndex, m_DelayBeforeLoad));
     }
 
     private IEnumerator WaitAndLoadScene(int sceneIndex, float delay)
     {
         yield return new WaitForSeconds(delay);
         SceneManager.LoadScene(sceneIndex);
     }
 }

However, it would be better to write a public function that you would call right after showing the text, in which case you'd need to replace private void OnEnable() by public void Load().

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 LoKo6264 · May 22, 2016 at 11:24 AM 0
Share

I copied and pasted this script but game changes to scene 2 immediatly after 3 seconds ins$$anonymous$$d after this ui text show up, any ideas?

After replace private void OnEnable()to public void LoadScene()I get error "'LoadScene': member names cannot be the same as their enclosing type".

avatar image corn LoKo6264 · May 23, 2016 at 05:51 AM 0
Share

If you use OnEnable, you need to attach the script to the GameObject to which the Text is attached, and disable it. You have to enable it only when the game is over.

As for LoadScene(), my bad, you cannot have a public function with the same name as the class, unless it's a constructor. Just call it Load() or whatever.

avatar image LoKo6264 corn · May 23, 2016 at 12:48 PM 0
Share

I made it on my own with different way, exactly ins$$anonymous$$d after "you won" game takes you to main menu after 3 seconds I made 2 buttons for go to main menu and exit from game. But of course thank you for help , you got Accept :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

54 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Application.LoadLevel is missing - Help please! 1 Answer

How to disable back button in android during unity splash screen display? 0 Answers

How to make toggles stay highlighted when clicking away 1 Answer

How to make it so that when quit menu is clicked then quit menu canvas pops up? 0 Answers

Game scene loads in background to Main Menu,Game level loads along with Main Menu 0 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