Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
-1
Question by grendayzer77 · May 20, 2014 at 06:32 PM · loadlevelswait

WaitForSeconds

hi, i used a code for my buttons to load my 99 levels, but i can't added WaitForSeconds to wait before loading a level, when i did it on a function my code bug.

any suggestion. Thanks

 public var sound1 : AudioClip;
 public var sound2 : AudioClip;
 
 private var i = 1;
 private var s : int;
 
 function Update ()
 {
     for (i=1; i<99; i++)
     {
         if (Input.GetMouseButtonDown(0))
         {
             var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
             
             if(hit.collider.name == "button"+i)
             {
                 audio.PlayOneShot(sound1);
                 s = i;
             }
         }
         
         if (Input.GetMouseButtonUp(0))
         {
             if (s == i)
             {
                 s = 0;
                 audio.PlayOneShot(sound2);
                 Application.LoadLevel ("Level "+i);
             }
         }
     }
 }
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 Jeff-Kesselman · May 20, 2014 at 06:36 PM 0
Share

No. Seeing as how you haven shown us either the code that actually failed, nor the error message spruced, none is likely to be able to help you.

As Such, this comes down to "write my code for me", something we don;t do here. If thats what you want I suggest you try the forums.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cryingwolf85 · May 20, 2014 at 07:06 PM

Sounds like you need to look over some Unity Scripting Basics.

Your problem sounds like a job for the Invoke method. Use it like this:

 // Will call the method LoadLevel after 5 seconds
 Invoke("LoadLevel", 5);


Comment
Add comment · Show 4 · 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 grendayzer77 · May 20, 2014 at 10:59 PM 0
Share

Thanks for the answer, but it seems to do the same thing as WaitForSeconds. Booth work good, and i tried WaitForSeconds in other script and i works great, but in this case, i have to press button 1 ("button "+i) and load level 1 ("Level "+i), when i use WaitForSeconds or Invoke, they don't do that. i think i should use them other way, but i don't know how. If you understand my problem, hope you have an other solution or the right way to use it.

avatar image cryingwolf85 · May 21, 2014 at 05:41 PM 0
Share

The way that you are going about this is wrong.

Problem 1: You trapped in a giant for loop. This is bad bad bad.

Problem 2: Don't set s = to i at all in this manner. Very messy. Find a more elegant solution if you continue this way.

Problem 3: Just the way that you are doing the GUI. Look at OnGUI. It's what you need for the buttons.

I Highly suggest you referring to the link I sent you in my previous comment. One read through this and you will be able to find solutions to simple problems much more easily.

avatar image grendayzer77 · May 28, 2014 at 09:06 PM 0
Share

Thanks for the advise, i'm beginner on unity and code so if you have a suggestion to di this code better, you are welcome.

avatar image cryingwolf85 · May 30, 2014 at 06:08 AM 0
Share

Those were my suggestions. I really do suggest your reading through the links, they will make your code better. I can't write your code for you, only you can!

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

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

level loader help m plzzzzz 1 Answer

Simple save/load scripting for multi level iOS game. 1 Answer

Wait n-seconds before loading level 1 Answer

How do I make sure a resource is loaded or is instantiated? 2 Answers

Load Level delay on collision C# 1 Answer


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