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 MrGoldenPorkchop · Feb 09, 2017 at 04:12 PM · javascriptcollidertriggerfunctionwaitforseconds

Can you help me with ''yield WaitForSeconds''?

Hello everyone! Can you help me? I was trying to add enemy AI and when enemy catches you you get jumpscared by it.I made it but after jumpscare i wanted to add "yield WaitForSeconds'' and ''Application.LoadLevel''... but it didn't work... Level didn't want to load! Could you write script for me that changes scene after some time? Thanks :)

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

Answer by HenryStrattonFW · Feb 09, 2017 at 08:00 PM

It would help to actually show us the code you're currently using as this may effect the kind of response you will get, and the best approach to take. But if we ignore any existing code, this is a Coroutine that would delay a scene load based on a delayTime (in seconds).

  private IEnumerator _DelayedLoad(float delayTime, string sceneToLoad)
  {
     yield return new WaitForSeconds(delayTime);
     
     SceneManager.LoadScene(sceneToLoad);
  }

You just then call this with StartCoroutine and it should do the job. so for example.

     public void GetJumpScared()
     {
         // Other jump scare stuffs.
         StartCoroutine(_DelayedLoad(2.0f, "MyScene"));
     }

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 MrGoldenPorkchop · Feb 09, 2017 at 08:18 PM 0
Share

Thank you so much :) I will test it now!

avatar image MrGoldenPorkchop · Feb 09, 2017 at 09:08 PM 0
Share

I get so many errors xD could you explain me where should i put those things? xD btw I already know that I have to add ''using UnityEngine.Scene$$anonymous$$anagement;

I'm getting "error CS1525: Unexpected symbol string', expecting ,', ;', or ='" and something like unexpected symbol "public" and sometimes "private".... help xD

sorry for taking your time

avatar image HenryStrattonFW MrGoldenPorkchop · Feb 09, 2017 at 10:20 PM 0
Share

Ah I should have mentioned, the script I provided was in C# are you using C# scripts or javascript? If using javascript this code whilst accurate in its process, will not be correct syntax which might explain the errors.

If however you are using C# can you please past the script you are currently using so that I can see it in it's entirety in order to try and work out what's going wrong.

avatar image MrGoldenPorkchop HenryStrattonFW · Feb 10, 2017 at 09:29 AM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class deathmenu : $$anonymous$$onoBehaviour {
     private IEnumerator _DelayedLoad(float delayTime, string deathmenu)    
     {
         void OnTriggerEnter(Collider theCollision)
         {
             if (theCollision.gameObject.tag == "Player")
             yield return new WaitForSeconds(3);
 
             Scene$$anonymous$$anager.LoadScene(deathmenu);
     }
 
 
     public void GetJumpScared
     {
         StartCoroutine(_DelayedLoad(2.0f,"H2"));
     }
 }







I deleted the code so I wrote it from my memory xD

Show more comments
Show more comments

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

146 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 avatar image avatar image avatar image avatar image

Related Questions

Can OnTriggerEnter2D trigger again once triggered? 0 Answers

OnTriggerEnter2D() function not working 1 Answer

Input Field URL browser. Please help! 0 Answers

Spawning with trigger 2 Answers

How to identify which collider generated OnTriggerEnter2D 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