Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mughalprince36 · Jun 19, 2016 at 08:09 AM · shootingprojectile

How to fire bullets from multiple guns at the same time?

I have a fighter jet which has 6 guns in it. I want to fire bullets with all six guns at the same time when i hit fire. The script used to fire bullet with 1 gun is attached below:

public class bullet_fire : MonoBehaviour {

 public GameObject Bullet_Emitter;

 public GameObject Bullet;

 public float Bullet_Forward_Force;
 
 // Use this for initialization
 void Start () {
 
 }
 
 
 // Update is called once per frame
 void Update () {
     if(Input.GetButtonDown("Fire1"))
     {
         GameObject temp_bullet_hsndler;
         temp_bullet_hsndler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
         temp_bullet_hsndler.transform.Rotate(Vector3.left * 90);

         Rigidbody temp_rigidbody;
         temp_rigidbody = temp_bullet_hsndler.GetComponent<Rigidbody>();
         temp_rigidbody.AddForce(transform.forward * Bullet_Forward_Force);
         Destroy(temp_bullet_hsndler, 3.0f);
     }
 }

}

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 thor348k · Jun 20, 2016 at 11:28 AM 0
Share

There is no need to have 6 of these scripts attached to each gun. Ins$$anonymous$$d, just attach this to your jet, and have a GameObject array, filled with the gun objects. Then when firing, just use a for loop to get each gun's position/rotation for spawning bullets.

Hope this helps! :)

2 Replies

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

Answer by thor348k · Jun 21, 2016 at 09:21 AM

I'd just have a Jet prefab, and a Gun prefab. Attach the shooting script to the Jet prefab, and use an array, which you can store the gun into (6 times). You'll need an array of positions to match each gun too, but that way, you can have many different types of jets, with many different types of guns!

If you're only wanting to use one type of Jet, and one type of Gun, just have 6 Gun prefabs as children on the Jet prefab, and assign them to the array in the shooting script attached to the Jet. That way you can avoid assigning positions.

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 mughalprince36 · Jun 21, 2016 at 07:41 AM

and if i use a prefab for this?

Comment
Add comment · Show 2 · 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 thor348k · Jun 21, 2016 at 08:22 AM 0
Share

A Jet prefab? Just make the Gun array public, and assign them via the Inspector.

avatar image mughalprince36 thor348k · Jun 21, 2016 at 09:11 AM 0
Share

I am currently using gun prefab. in which each gun has the same script assigned. Is it better or using array is better?

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

45 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 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

2D projectiles not rotating 0 Answers

Basic FPS help! 2 Answers

Projectile trajectory based on angle 0 Answers

how I can control projectile shooting limit??? 0 Answers

How to instantiate projectile at the right height? 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