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 Nathan Bennett · Dec 16, 2010 at 07:05 PM · fixedupdatelasersecond

how to instantiate an object every second?

hello. i just wanted to know how to instantiate a object every second? (in this case a laser beam) i have tried using Time.deltaTime, but it still isn't playing ball. (when debugging(on fastest), it still is firing alot faster then in the editor?).

i've even tried invokeRepeat(function(string),time(int), seconds (int)) but still no joy? how do i get unity to do a certain thing at a consistent speed on any computer! i could try fixedUpdate but i don't really fancy separating if(GetAxis("Fire1")) in too two functions as it will overload a first animation i have.

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

2 Replies

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

Answer by Mickydtron · Dec 16, 2010 at 07:23 PM

try having a variable store the last time you fired. then you can check if a second has passed, and if it has, fire and set the last fired time to now.

 var lastFired = 0.0;
    if(( Time.time > lastFired + 1.0)&&(GetAxis("Fire1"))
    {
        //fire lasers!
        lastFired=Time.time;
    }
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 Nathan Bennett · Dec 17, 2010 at 06:27 PM 0
Share

Thanks Very much!

avatar image
0

Answer by Statement · Dec 16, 2010 at 08:18 PM

i've even tried invokeRepeat(function(string),time(int), seconds (int)) but still no joy?

var laserPrefab : GameObject; var timeBetweenLasers : float = 0.5f;

function Update() { if (Input.GetButtonDown("Fire1")) InvokeRepeating("FireLaser", float.Epsilon, timeBetweenLasers); if (Input.GetButtonUp("Fire1")) CancelInvoke("FireLaser"); }

function FireLaser() { if (!laserPrefab) { Debug.LogWarning("You forgot to set the laser prefab!"); return; }

 Instantiate(laserPrefab, transform.position, transform.rotation);

}

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 Statement · Dec 16, 2010 at 08:19 PM 0
Share

The float.Epsilon (smallest positive float value) is there because if you have 0, for some reason you get 3 calls to FireLaser in case you tap the button.

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

No one has followed this question yet.

Related Questions

Physics behaviour changing with framerate - Is FixedUpdate() actually working properly? 3 Answers

Camera rotate around a moving object: fixedLateUpdate? 1 Answer

Is it possible to create a second FixedUpdate function running at different rate? 2 Answers

Fixed Update Time, Object Stop moving 0 Answers

FixedUpdate and LineCast? 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