Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TGKG · Dec 21, 2015 at 04:33 PM · errorwhats-wrong

Invoke acting strange

I am using an Invoke command to end my game after displaying an exit scene for a few seconds. When I open this scene I want it to display for a few seconds and then I want the game to stop. In the inspector I have "quitTime = 2" using UnityEngine; using System.Collections;

 public class QuitGameAfterTime : MonoBehaviour {
 
     public float quitTime;
 
     void Awake () 
     {
         print ("QuitGameAfterTime: Awake, quitTime=" + quitTime);
         Invoke("QuitGame", quitTime);        
     }
 
 
     void QuitGame()
     {
         print ("QuitGameAfterTime: QuitGame");
         #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
                 
         #elif (UNITY_IPHONE)
         Application.Quit();
 
         #elif (UNITY_ANDROID)
         Application.Quit();
                 
         #else
         Application.Quit();
         #endif
     }
 }
 

When I run my game and go directly to the exit scene everything works fine and the game ends after 2 seconds. Even if I go to a credits scene or goto a settings scene and then go to the exit scene everything works fine (game ends after 2 seconds). However if I play my game, leave the game scene and then go to the exit scene it does not work. The Awake function runs but the Invoke never does. This is a very consistent problem. I have no idea what could be part of my game to cause this?!?! Does anyone have any ideas?

Comment
Add comment · Show 1
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 TGKG · Dec 22, 2015 at 06:04 PM 0
Share

I know this is a vague question, however does anyone have an idea of what could cause Invoke to NOT execute?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TGKG · Dec 23, 2015 at 05:46 PM

Okay, Problem Solved (I feel like a bit of a fool) !! The way I exit my game is to press the pause button and within the pause menu press the return button to get me to the main menu (I can tell some of you already know where this is going) :)

As it turns out, when I pause the game and press return I never reset the Time.time = 1.0. THUS, Invoke did not work on exit. So simple yet so obvious now!!

Before you ask, yes I had a Time.time = 1.0 when starting my game so everything else worked as it should.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What the heck is this? 1 Answer

Object reference not set to an instance of an Object C# 2 Answers

Why doesn't enabling and disabling not work? 1 Answer

Warnings in Java 0 Answers

object reference not set to an instance of an object Player.Damge (Single count) (at Assets/Player.js:31) 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