Executing code with an order

Hello everyone. I have a weapon in my game and the bullets can be seen by the player. So I want them to be invisible when player fires, like they are really going through the weapon barrel and shooting. So I want to make them invisible one by one, with order.I thought creating an array and doing it with array list but I don’t know how to do that. Like this :

if ( Input.GetButton("Fire1")) {
Make the first element of array invisible }

but if player continue firing, after the first element is invisible, then the second will be invisible then the third then the fourth, it will go if player keeps firing. So any idea how to do that ? Or is there any other way to execute a code to gameobjects with an order ? Thanks :slight_smile:

I would use a data container to help me keep the order of the bullets.

Create a queue/list of bullets e.g. GameObject:

List<GameObject> bullets = new List<GameObject>();

Now if you add all new bullets to the end and remove old bullets from the front, you have ordered the bullets in the list.

If not sure about lists, please read it up on MSDN. You want to use them :wink: