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
0
Question by Digital-Phantom · Dec 21, 2014 at 04:08 PM · javascriptyield waitforsecondsfunction call

Custom Function not working ?

Can somebody tell me why the custom function (think that's the right term) the function newFunction part of my script doesn't work. I get no errors and the rest of the script works fine but it's like the newFunction is just completely ignored by the game ?

 #pragma strict 
        
 public var Boulder : GameObject;
 public var BoulderLimit : int; // the max amount of Boulders that can be spawned    
 public var BoulderCount : int; // the current amount of spawned Boulders    
 public var spawnBoulder : boolean; // if the Boulders are allowed to spawn
     
 function Update ()
 {
     if ( BoulderCount < BoulderLimit ) // check if the current spawn amount is below the limit  
     {
         SpawnBoulder (); // spawn the Boulder
     }
     else
     {
         spawnBoulder = false;
         Debug.Log ( "Spawn Limit Has Been Reached!" );
     }
 }
     
     
 function SpawnBoulder () // spawn the GameObject
 {
     Instantiate(Boulder, transform.position, transform.rotation);
     BoulderCount++; // add to the current amount of spawned Boulders
     Debug.Log ( "Spawned GameObject #" + BoulderCount );
     
     newFunction();  
 }
     
 function newFunction()
 {
     yield WaitForSeconds(8);
     BoulderCount--;
     Debug.Log ( "Boulder Count Reset!" );
 }

Any ideas guys ?

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 meat5000 · Dec 21, 2014 at 04:32 PM

Your functions needs to be upgraded to a coroutine.

yields and waitforseconds can only be used there.

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 Digital-Phantom · Dec 21, 2014 at 04:40 PM 0
Share

unfortunately that's beyond my level of coding at the moment. Will look into it though, thanks

avatar image meat5000 ♦ · Dec 21, 2014 at 04:42 PM 0
Share

Just click the link, its all in there. It actually really easy @Digital-

( Strange how your Handle is @Digital- :P )

avatar image Digital-Phantom · Dec 21, 2014 at 05:01 PM 0
Share

Without wanting to make myself seem dumb, I thought that's what I'd done? I called a new function, put my WaitForSeconds with a yield statement, but the rest of the function doesn't happen? I only want the bouldercount to reset to zero

avatar image meat5000 ♦ · Dec 21, 2014 at 05:08 PM 0
Share

Yeah you're right, I'm being dumb and looking at the C# page.

Your function should work just fine.

Do you see Spawned GameObject #" + BoulderCount Debug?

and

Boulder Count Reset! ?

avatar image AlucardJay · Dec 22, 2014 at 02:38 AM 0
Share

Yep, thought I had it, then just got more confused.

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

28 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

Related Questions

Yield Never Works 4 Answers

Setting Scroll View Width GUILayout 1 Answer

Trying WaitForSeconds before Instantiating 2 Answers

Scripting Heart BPM Using Different Values With Switch & Yield 2 Answers

yield waitforseconds doesnt work on function start 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