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 Bigfootstoe · Apr 23, 2017 at 12:54 AM · collisionscenescene-loadingglitchreset

How do you call a function once

So I Created a function that runs with

     void OnTriggerEnter(Collider other)
 {
 if (other.gameObject.CompareTag ("Ocean"))
             {
                 SceneManager.LoadScene("minigame", LoadSceneMode.Additive);
             }        
 }

The problem is it collides about 4 times before the seen is actually loaded, so then the scenes get stacked on top of each other and all run at the same time. I am new to unity and don't know how to fix this. Please help. Once I get this done I will almost have my game finished, so thank you for your help. @SohailBukhari

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
0
Best Answer

Answer by TeohRIK · Apr 23, 2017 at 01:41 AM

use boolean

 private bool loadSceneCalled = false;
 
 void OnTriggerEnter(Collider other)
  {
 
 if(loadSceneCalled)
      return;
 
  if (other.gameObject.CompareTag ("Ocean"))
              {
                  SceneManager.LoadScene("minigame", LoadSceneMode.Additive);
                  loadSceneCalled = true;
              }        
  }
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 Bigfootstoe · Apr 23, 2017 at 02:57 PM

Alright, that worked, but I still have a problem. It doesn't close the already open scene, so I still have two running at the same time, the current scene and the old one. How do I fix that? Btw, The answer was beautiful thanks @walaoRIKI

Comment
Add comment · Show 5 · 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 TeohRIK · Apr 23, 2017 at 03:05 PM 0
Share

oh...you just change the LoadScene$$anonymous$$ode.Additive to LoadScene$$anonymous$$ode.Single

Or juz call the load scene function like this

 Scene$$anonymous$$anager.LoadScene("$$anonymous$$igame");
avatar image Bigfootstoe TeohRIK · Apr 23, 2017 at 03:18 PM 0
Share

This still will not work. I need to be able to close the current scene and then run the Scene$$anonymous$$anager.LoadScene("$$anonymous$$igame");

In that order. Thanks

avatar image Bigfootstoe TeohRIK · Apr 23, 2017 at 03:27 PM 0
Share

If I do that should I keep the boolean or not? Also, How do you close a scene? Thanks

avatar image TeohRIK TeohRIK · Apr 24, 2017 at 01:03 AM 0
Share

I need to be able to close the current scene and then run the Scene$$anonymous$$anager.LoadScene("$$anonymous$$igame");

$$anonymous$$aybe you can switch to a blank or black scene or I call it a loading scene first and then only switch to the scene you want

If I do that should I keep the boolean or not? Also, How do you close a scene? Thanks

If you switch to another scene then only switch to $$anonymous$$i game scene then no need the boolean. Usually before I switch the scene I will turn on a black panel with Loading text from UI canvas first then only call the LoadScene function, if I want to have some fancy loading animation then I will use loadsceneasync to load the on blackground.

avatar image Bigfootstoe TeohRIK · Apr 24, 2017 at 09:05 PM 0
Share

It works! I reset my computer and its all better!

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

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

Scene Reset on HTC Vive Idle? 0 Answers

Scene Editor Problem @username 0 Answers

Game Object adds itself back after scene reload? 1 Answer

garbage collection in between scene changes? 2 Answers

Restarted scene not working properly 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