• 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 /
This question was closed Feb 29, 2016 at 09:43 PM by Matocrash for the following reason:

Other

avatar image
Question by Matocrash · May 10, 2014 at 10:22 AM · javascriptnoobnewrestart

Restart Level not working...

So, what I'm trying to do is,an exploding coin, that would restart the level when you colect it. here is my code:

 var coinExplosion : Transform;
 
 function OnTriggerEnter (info : Collider) 
 {
   if (info.tag == "Player")
   {
   var effect = Instantiate(coinExplosion, transform.position, transform.rotation);
   Destroy(gameObject);
   yield WaitForSeconds(0.5) //Time for the explosion to end
   Application.LoadLevel("Level1");
   }
 }

The coin explodes and everything, but the level doesn't restart... Tell me if you need more info. Thank you in advance,

Mato

Comment

People who like this

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

Answer by AlucardJay · May 10, 2014 at 10:24 AM

You are destroying the gameObject, so it cannot wait for 0.5s because it is not there anymore! You need to rethink how you are going to call Application.LoadLevel

please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

Comment
Professor Snake

People who like this

1 Show 2 · 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 felixpk · May 10, 2014 at 02:26 PM 0
Share

Why would you want to Destroy the GameObject if you reload the scene anyway? And you may use: Application.LoadLevel(Apllication.LoadedLevel);

now you can reuse it for every Level you have

avatar image Matocrash · May 10, 2014 at 02:33 PM 0
Share

Thanks, I got it now... I feel like an Idiot

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

I know javascript but i don't understand Unity's javascript! 1 Answer

musket gun script is not working 3 Answers

Problem when creating a projectile for a weapon. (FIXED) 1 Answer

Pause Button Help 2 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