Smartest way to Instantiate different objects on different times.

EDITED: SEE BELOW! First Question is answered!

Hi folks,

I cant figure it out, how i would make a function wich i dont need to copy/paste all the time, when i want to add new object to instantiate.

Here is mini version of my code.

static var checkPrize = false;
    var good : GameObject;
    
    function Start () {
    checkPrize = false;
    }
    
    function Update () {
    score = otherScript.score;
    
    //IF FUNCTION
    if (score == 5 && checkPrize == false) {
    checkPrize = true;
    var pos = new Vector2(2, 0);
    var rot : Quaternion= Quaternion.identity;
    Instantiate (good, pos, rot);		
    }
    		
    }

I would like to edit these two things in inspector:

  1. if SCORE is 5, then instantiate object GOOD
  2. if SCORE is 10, then instantiate object COOL
  3. if SCORE is 20… and so on.

Otherwise i would need to copy and paste same code for every new object i want to instantiate.

What would be the best solution? Or just easiest if not the best!
Thanks!

-----EDITED-----

Okay, this seems to be working fine, but next question is HOW TO instantiate Object once?

//Check if score 5 is gone, to set checkPrize back to false
if(score = 6 && checkPrize = true) {
checkPrize = false;
}
//Check if score 10 is gone, to set checkPrize back to false..
if(score = 11 && checkPrize = true) {
checkPrize = false;
}


if(checkPrize == false){
    
    var pos = new Vector2(2,0);
    var rot : Quaternion = Quaternion.identity;
    switch(score){
          case (5):
          Instantiate (good, pos, rot);
          checkPrize = true;
          break;

          case (10):
          Instantiate (good, pos, rot);
          checkPrize = true;
          break;

}

Okay, this solution works, but is there ANYWAY to do it easier? Maybe without BOOLEAN??

The question is - how to instantiate object once, but allow to instantiate next one, without instantiating same object multiple times while score is 5 or 10.

Easiest way is to use a Switch statement, like so.

if(checkPrize ==false){
   checkPrize = true;
   var pos = new Vector2(2,0);
   var rot : Quaternion = Quaternion.identity;
   switch(score){
         case (5):
         Instantiate (good, pos, rot);
         break;
       
         case(10):
         Instantiate (cool, pos, rot);
         break;
   }
}

But the best way I can think of if you have a lot would be to use a Dictionary but that takes more work and understanding to set up. (look up Dictionary Keyvaluepair if you are interested.

It would allow you to do something like

Instantiate(Reward[points],pos,rot);

WUCC

Good luck.