Making an object/prefab disappear after being used several times

I am working on a horror game (mostly testing out scripts I am working on because I am very new to scripting), and I have two pretty cool scripts: a flare, that is thrown across the room and disappears after a few seconds, and a glow stick that you can set down to remember places. I want to do two things with these scripts: A.) I want to only be able to throw one flare at a time, in other words to throw one flare, and you can only throw another flare after the one you have thrown has completely disappeared. B.) I want there to only be about 5 glow sticks available at a time. To be more clear, you can only have 5 glow sticks present at a time. once you put down a 6th glow stick, the first one disappears, once youve put down a 7th, your 2nd stick disappears, so on and so forth. Since I am fairly new to scripting I cannot figure out scripts for these to save my life. Yes, I do have the Flare and glow stick scripts done, so dont help me on those, just “A” and “B”. dont just give me a script for this, explain how it works too. That way I can either reference a script and start to understand how it works, or see your feedback and develop my own script. This is learning for me, just handing me a script wont teach me a whole lot. If you do just post scripts for these, thats fine, I can still study it. Sorry if this is too long or unclear, but I am fairly new to Unity Forums and will try to be more clear in the future and in my responses.
Best regards!

The first can be done multiple ways. A simple way would be creating a Boolean for the ability to shoot a flare, and then use coroutines to wait for the amount of time the flare takes to disappear, and change the Boolean back to being able to shoot. The second is somewhat more complicated. You should look into arrays.

Alright I understand booleans a little, and from what I remember they are quite simple. Isn’t it just used as a comparing statement? Not quite sure what a “coroutine(s)” is, maybe you could give me some insight? I will look both up, and I will look up arrays as well. thanks for the feedback!

The documentation does a pretty good job of explaining what coroutines are and how to use them. Look here for more information.

Sorry to continue bothering you, but I am having a bit of trouble with this. I have been studying this article, but since I have not completely followed Unity’s tutorials, and have been (for the most part) watching Youtube tutorials on scripting and programming, this approach is a bit confusing. The Flare Script I wrote is this:

var FLARE : Transform;
var throwStrength : float;
var flareGone : float;

function Update () {

if(Input.GetButtonDown(“throwFLARE”)) {
var instanceThrow = Instantiate(FLARE, transform.position, Quaternion.identity);
instanceThrow.rigidbody.AddForce(transform.forward * throwStrength);

}

}

I don’t understand where I would even put the Coroutine/yield script, considering it does not work in a function Update. I put it under a function Start at one point, but I dont know how to “word” it there, or even in any way that would work. I still have yet to look into arrays. This is the script to make the flares disappear. Once again, I have no idea which of these scripts I would put the coroutine (or yields), or if I can even put them in a seperate script. Here it is:

#pragma strict
var flareGone : float;

function Start () {

}

function Update () {
flareGone -= Time.deltaTime;

if(flareGone < 0.0) {
gameObject.Destroy(gameObject, 1.0);
}

}