I want to trigger particle with collectable

I want to start particle system on terrain only when the player have collect all 4 collectables in my map, but my script doesn't work.I want it to start from when the guitexture I made was complete with 4 colletables and I made this script to do the job:

function start () {

     if(guiTexture.texture == 4) {
        particleEmitter.emit = true;
        guitexture.enabled = true;
      }
      else if (guiTexture.texture <= 4){
        particleEmitter.emit = false;
}

I dont realy understand what I am doing wrong,if I put this in the wrong place or if a create it in the wrong files, I put em in the particle prefab that i made and have associated with. I am not so good in understanding code, so someone can help me, give me some advice, so I can figure out what I am doing wrong. Thanks for your time.

Sam

If you put a function in start() it'll only ever be executed once.. at the start.

If you want to check every frame if the player has something you do it in Update()

If you wanted to check if the player has 4 or more of something and then start a particle effect you do this:

function Update(){
   if(itemNumber>=4){
       Instantiate(particleEffect,transform.position,transform.rotation);
   } else {
       // don't do anything
   }
}

Where particleEffect is a prefab you made of the particle effect

So, after many headache along the last week-end I finally solve my problem. So here I have the code who work for my project;

static var carte : int = 0;

var  carte1tex : Texture2D;
var  carte2tex : Texture2D;
var  carte3tex : Texture2D;
var  carte4tex : Texture2D;
var  carte0tex : Texture2D;

function Start () {
guiTexture.enabled = false;
carte = 0;
}

function Update () {
   if (carte == 1) {
      guiTexture.texture = carte1tex;
      guiTexture.enabled = true;
   }
   else if (carte == 2) {
      guiTexture.texture = carte2tex;
   }
   else if (carte == 3) {
      guiTexture.texture = carte3tex;
   }
   else if (carte >= 4) {
      guiTexture.texture = carte4tex;

    var flames : GameObject = GameObject.Find("particlegroup");

    var flameEmitter : ParticleEmitter = flames.GetComponent(ParticleEmitter);
    flameEmitter.emit = true;

    var smoke : GameObject = GameObject.Find("particlegroup_b");

    var smokeEmitter : ParticleEmitter = smoke.GetComponent(ParticleEmitter);
    smokeEmitter.emit = true;

    Destroy(GameObject.Find("Map_GUI"));
   }
   else{
      guiTexture.texture = carte0tex;
   }

}

The story was that my code was really off the track. I have create a first script separated of my other script who made me collect my collectible, so this won't work for the particle. Today I ask my teacher for help. He tell me who was a campfire already as an example for the course so we use the part about the campfire who was started by a trigger whit a collectible .match. I delete my old script and I use it in my collectible script and it work well.

So my principles mistakes was:

  1. Creating a new script for my particle only.
  2. Creating a wrong code because I

    don’t understand it so well.my bad.

  3. Don't strip the emit case in my

    particle element in the Hierarchy to
    disabled it.

  4. Have associated my old script in the particle prefab I have create. I don't understand why but the teacher tell me to don't do that because it is not necessary so I erase it.

I don't understand at all the instantiate you have suggest. But thank you for your help spinaljack.

So this is only my collectible script I have made earlier for my collectible only, you can see the difference for yourself and see what I was missing.

static var carte : int = 0;

var  carte1tex : Texture2D;
var  carte2tex : Texture2D;
var  carte3tex : Texture2D;
var  carte4tex : Texture2D;
var  carte0tex : Texture2D;

function Start () {
guiTexture.enabled = false;
carte = 0;
}

function Update () {
   if (carte == 1) {
      guiTexture.texture = carte1tex;
      guiTexture.enabled = true;
   }
   else if (carte == 2) {
      guiTexture.texture = carte2tex;
   }
   else if (carte == 3) {
      guiTexture.texture = carte3tex;
   }
   else if (carte >= 4) {
      guiTexture.texture = carte4tex;
    Destroy(GameObject.Find("Map_GUI"));
   }
   else{
      guiTexture.texture = carte0tex;
   }

}

Lot to learn! hope this help somebody else

note: "particle group" and "particle group_b" is my particle prefab

"Map_GUI" is the group who I put the GUItexture and the collectable script I create for my collectable system earlier.

Thank you everybody

Sam