Search Unity

How to shoot multiple bullets ar once

Discussion in 'Scripting' started by slidecoast, May 25, 2013.

  1. slidecoast

    slidecoast

    Joined:
    Nov 6, 2012
    Posts:
    24
    I have my character shooting bullets in the game. But I want to know how my character can shoot multiple bullets at once.

    Here is the example: https://www.youtube.com/watch?v=-H2ka0kH71s

    Can someone show how to make my character or weapon shoot multiple bullets at once, per click?

    My Shooting code:

    var playerProjectile: GameObject;

    Code (csharp):
    1.  
    2. function Update () {
    3.  
    4.     if(Input.GetKeyDown("space")  Time.time > nextShot){
    5.  
    6.        nextShot = Time.time * timeBetweenShots;
    7.  
    8.        Instantiate(playerProjectile, _transform.position, Quaternion.identity);
    9.     }
    10.  
    11. }
    12.  
     
  2. MH1

    MH1

    Joined:
    Mar 31, 2013
    Posts:
    7
    Take away the word "Down". This will make it so that when you hold down the space bar your weapon will shoot continuously.
     
  3. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    Something similar to the following may be what you need, as a replacement to the single shot you have firing now.

    Code (csharp):
    1.  
    2. for(int i = 0; i < numberOfShotsVariable; i++)
    3. {
    4.    Instantiate(playerProjectile, _transform.position, Quaternion.identity);
    5. }
    6.