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:
- if SCORE is 5, then instantiate object GOOD
- if SCORE is 10, then instantiate object COOL
- 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.