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 /
avatar image
0
Question by Diamonddoggames · Jul 23, 2017 at 07:44 PM · scene

Trigger a scene with a timer

I have been looking for a timer that can trigger a scene when it hits 0 and there is no GUI please help unity 5.5

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FlaSh-G · Jul 23, 2017 at 08:59 PM

A very easy (although not very robust) way to do this is the Invoke method. Like this:

 void OnTriggerEnter() // For example
 {
   Invoke("ChangeScene", 10); // 10 seconds delay
 }

 void ChangeScene()
 {
   SceneManager.LoadScene("Some scene");
 }

You can improve this code a bit by using nameof:

 void OnTriggerEnter() // For example
 {
   Invoke(nameof(ChangeScene), 10); // 10 seconds delay
 }

 void ChangeScene()
 {
   SceneManager.LoadScene("Some scene");
 }
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
0

Answer by drakedane · Oct 12, 2017 at 07:55 PM

@ Diamonddoggames Not sure if the answer above worked for you; but I use something closer to what you described. This is only a temporary feature that I intend to remove, but once certain scenes are loaded, a timer starts. When timer reaches 0, the scene auto switches back to the original scene. The way it was designed, the countdown displays on-screen, but you don't have to do that.

Here is the code I use. I tried to strip out everything but the timer scripting.

 public class Timer : MonoBehaviour 
 
    {
    
     
        public string leveltoload;
        
             private float timer = 10f;
    
             private Text timerseconds;
    
        
 
             void Start () 
        
             {
    
                         timerseconds = GetComponent<Text>();
    
             }
    
 
     
        void Update () 
        
                 {
                    
            timer -= Time.deltaTime;
    
                            timerseconds.text = timer.ToString("f0");
     
                            if (timer <= 0)
    
                            {
    
                         Invoke("LoadScene", 2.5f);
    
                    }
        
                   }
 
 
    
                    void LoadScene()
    
                 {
    
                  SceneManager.LoadScene("OLYMPUS");
    
             }
 
    }
 
Comment
Add comment · Show 1 · 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 budev · May 17 at 11:36 PM 0
Share

For more begginers, you may change Private to Public and add this on top,

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;

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

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

Help with loading a scene,Help changing scenes (C~ script) 1 Answer

Best practices about shared objects 0 Answers

obb apk scene load fail 1 Answer

Prefab wont appear in game view but appears in scene view when called from CSV file. 2 Answers

Same script not working on next level 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