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 /
This question was closed Apr 30, 2014 at 11:21 AM by Hexer for the following reason:

The question is answered, right answer was accepted (although it isn't really a awnser but a redirect to a Unity ScriptReferance)

avatar image
2
Question by Hexer · Apr 30, 2014 at 11:11 AM · random.rangefunction update

Call function every second.

Hello, I was just wondering.

Is there a way to call a function each second instead of 60x a second,like function Update() does.

I have tried to put a yield each time after it calls the function but that doesn't work either.

Well this is the script I made. Each time (or 60x a second because of Update().) it picks a random number ranged from 0 to 4. "Spawn" is equal to that number that has been chosen. This all works well only it Updates way to fast. I tried to put a "yield WaitForSeconds(1);". With no succes.

 function Update()
 {
  var Spawn = Random.Range(0,4);
  
   if(Spawn == 0){
   Debug.Log("spawn0");
  
  }
   if(Spawn == 1){ 
   Debug.Log("spawn1");
   
  }
   if(Spawn == 2){ 
   Debug.Log("spawn2");
    
  }
   if(Spawn == 3){ 
   Debug.Log("spawn3");
  
  }
   if(Spawn == 4){ 
   Debug.Log("spawn4"); 
  
  }
 }

Thanks for reading.

Comment
Add comment · Show 2
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 Nerevar · Apr 30, 2014 at 11:13 AM 0
Share

Hello,

maybe this is what you need: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html

regards.

avatar image Hexer · Apr 30, 2014 at 11:19 AM 0
Share

Yes thanks for your Awnser :). That was exact what I needed

1 Reply

  • Sort: 
avatar image
6
Best Answer

Answer by fafase · Apr 30, 2014 at 11:14 AM

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html

Comment
Add comment · Show 1 · 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 Hexer · Apr 30, 2014 at 11:18 AM 0
Share

Yes thanks, thats what I needed :). I also found it in another Awnser : link text

 InvokeRepeating("YOUR FUNCTION NA$$anonymous$$E", 0, 1.0);

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Lasers Fire over and over 2 Answers

Random.Range only returns lowest value 1 Answer

Make a sum once per time, in the update function 1 Answer

How Can I Reference A Range e.g. Between -90 & 90 1 Answer

Function that starts on game startup but doesn't update on scene change. 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