• 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 Dec 01, 2015 at 02:09 AM by Codelyy.
avatar image
0
Question by Codelyy · Dec 01, 2015 at 12:33 AM · 3dfiring

Fire 3 bullets only, one after the other

I'm wanting to create a boss fight and I'm using states to do it. I want one of the functions in my state to fire 3 bullets only at the player but one after the other so they don't collide with each other and come out all at once. Sadly i don't know how to do this.

I did try and it just ended up with the bullets coming out all at once instead of one after the other like i wanted.

Any help?

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

  • Sort: 
avatar image
0

Answer by toddisarockstar · Dec 01, 2015 at 01:25 AM

 function Update () {
 
   var timer:float;
  var gunnumber:int;
  var bulletonce:int;
  var delay:float;    //----time between shots
  
 
  if(Input.GetKeyDown("space")){gunnumber=3;timer=3;} 
  
  if(gunnumber>0){
  timer=timer-Time.deltaTime*delay;
                      if(timer<0){timer=3;
                                          gunnumber=gunnumber-1;}}
  
  
  
  if(gunnumber!=bulletonce){
                     bulletnumber=bulletonce;
  
  //----------------------trigger a bullet here however you are doing that. lol!!!!!!
  
  }}
Comment
Add comment · 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
0

Answer by ZefanS · Dec 01, 2015 at 01:21 AM

You could add a delay in between firing the bullets like this:

 var delayTime = 0.5;
 var startTime = Time.time;
 while (Time.time - startTime < delayTime)
 {
     yield;
 }

Note that the yield statement will technically make your function into a coroutine. As a result, this will be slightly more complicated to implement in C#. See here for more on coroutines. There may be other ways to achieve this functionality if this route seems unappealing to you.

Comment
Add comment · 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

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

33 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy only moves in a line 1 Answer

How to change a prefab's pivot point to exactly its center? 0 Answers

2 camera view render 1 Answer

Character keeps jumping on uneven terrain 0 Answers

iPhone game with free Unity? 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