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 /
This question was closed Jul 16, 2017 at 09:34 AM by EGGamer for the following reason:

La pregunta fué respondida y una respuesta ha sido aceptada

avatar image
0
Question by EGGamer · Jul 15, 2017 at 04:37 PM · triggerloadlevelasyncasynchronous

Load level async

Hi, I've seen this video: https://www.youtube.com/watch?v=YMj2qPq9CP8& And I would like, instead of changing the scene showing a load bar pressing a ui button, was with a trigger. I have created two scripts, one that shows in the above mentioned video and another one that activates the other script when passing through the trigger:

Script 1 (script of the video):

public void LoadLevel (int sceneIndex) { StartCoroutine(LoadAsynchronously(sceneIndex));
} IEnumerator LoadAsynchronously (int sceneIndex) { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex); while (!operation.isDone) { Debug.Log(operation.progress); yield return null; } }

}

Script 2 (that activates the above script with the trigger):

public class "2nd script name" : "1st script name" {

void OnTriggerEnter () { LoadLevel(); } }

I have worked by putting the value of the sceneIndex inside the script, but I do not want to repeat the same script for each scene I will do, which I want from the inspector to be able to edit "int sceneIndex" but, I have not gotten the form to do it.

I hope someone can help me. Thank you very much.

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

  • Sort: 
avatar image
1
Best Answer

Answer by Kaskorian · Jul 15, 2017 at 05:21 PM

I don't understand the last part of your question. you want to load async in OnTriggerEnter() and you want to edit the sceneIndex via Inspector.

Is that right?

Comment
Add comment · Show 6 · 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 EGGamer · Jul 15, 2017 at 06:00 PM 0
Share

Yeah thats right

avatar image Kaskorian · Jul 15, 2017 at 07:39 PM 1
Share

Ok so here is a solution.

You can do it in one script. And you put the script on the game object with the trigger

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;

public class LoadScene : $$anonymous$$onoBehaviour { public int sceneIndex;

 void OnTriggerEnter(Collider other)
 {
     Debug.Log("Hallo");
     StartCoroutine(LoadAsynchronously());
 }

 IEnumerator LoadAsynchronously()
 {
     AsyncOperation operation = Scene$$anonymous$$anager.LoadSceneAsync(sceneIndex);
     while (!operation.isDone)
     {
         Debug.Log(operation.progress);
         yield return null;
     }
 }

}

avatar image EGGamer Kaskorian · Jul 16, 2017 at 09:34 AM 0
Share

It works! Thank you very much. I did not expect it to be that easy.

avatar image Kaskorian · Jul 15, 2017 at 07:44 PM 0
Share

and be careful. One of the objects has to have a Rigidbody Component otherwise, the collision is not detected.

avatar image EGGamer Kaskorian · Jul 16, 2017 at 09:18 AM 0
Share

Yeah, I know. Thanks.

avatar image Kaskorian EGGamer · Jul 16, 2017 at 09:34 AM 0
Share

you're welcome

Follow this Question

Answers Answers and Comments

83 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

Related Questions

Load Scene in Background and Load When a Button is Clicked 0 Answers

Async Level loading issue. 0 Answers

How to properly call Async Task 0 Answers

Unity, WebClient, Upload, Async and Threads. 0 Answers

How to wait for WWW to finish without Coroutine. 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