- Home /
Set destroy order
Hello, I would like to implement something for my game, but I don't know how or where to start. I would like to set a destroy order, a good example of this is that I have a red ball and has a Number 1 that indicates that the player needs to destroy that ball first and so on, and if he/she destroys other balls they lose.
Answer by someonethatis · Jun 09, 2020 at 10:03 PM
lest's say you have 3 balls
note I'm typing code on this so don't get mad when it looks weird
you can go
GameObject ball1;
GameObject ball2;
GameObject ball3
void Update(){
if(ball1 != null && ball2 = null)
{
// lose
}
if(ball1 != null && ball3 == null){
//lose
}
if (ball2 != null && ball 3 == null){
//lose
}
// put this at the end
if(ball1 == null && ball2 == null &&ball3 == null){
//win
}
}
or
you can use a index like this (this might not work but probably can be modified to work)
GameObject[] balls = new GameObject[However many balls];
//you need to go to the inspector and put the balls in order to what you want to destroy first
void Update()
{
foreach (GameObject ball in balls)
{
int minisIndex = 0;
int OminisIndex = 1;
int index = 0;
if (OminisIndex <= 1)
{
minisIndex = OminisIndex;
for (int i = 0;i==minisIndex;i+=0) {
if (balls[minisIndex] != null && balls[index] == null)
{
//lose
}
minisIndex--;
}
}
index++;
OminisIndex++;
}
}
tell me if this was help full
Answer by cesarpc1998 · Jun 09, 2020 at 10:56 PM
@someonethatis I have a problem because if I have different levels with different Ball quantities the script won't work
Yes, I did some modification and it works, your answers were helpful!
Do you think you can fix it just let me know @cesarpc1998