Hello creators!
I’m trying to build a space base protection that works automoatically. When an enemi is detected, 2 ships are selected to go and protect the base. I don’t want that is allways the same ships that go, i want to make a turn by turn (they are 16 ships, if the first and second one are going to fight and comming back, on the next alert, the ship 3 4 will be sellected , then 4, 5 and etc…) When all the 16 ships was going to fight, the first one will be sellected again, and it should loop like this.
For that, i was creating an empty game object that represent a disponibility switch (i was going to fight this turn, i’m waiting the next / i’m ready to fight, it’s my turn) When this game object is active, the ship can be sellected if an alarm occurs, if he is not active, he is “busy” and can not be sellected until the next turn.
So in the theory, should work… but my script seems to have some errors… if someone can help so solve it.
(errors : the empty that represent the disponibility of the ship should turn inactive if he is choosen, but he don’t turn inactive ; When the ships go, they need to have a fixed position in the trooper for play a specific animation, so in my script i put the first ship sellected in the first position of the trooper, the second sellected in the second place etc… i can not assign the sellected game object to another variable that represent the same game object…)
The script:
var dispo = new GameObject[16]; // the game object that define if the ship is disponible or not
var ship = new GameObject[16]; // the ship himself, for play the animation
private var elu = new GameObject[1]; // this is the variable that supose to take the valor of the sellected game object for the position in the trooper
var i = 0;
var j = 0;
function Start ()
{
yield WaitForSeconds(2);
Alert2();
yield WaitForSeconds(5);
Alert2();
yield WaitForSeconds(5);
Alert2();
}
function Alert2()
{
for (j = 0; j == 2; j++) // the condition loop until we find 2 ships availlables.
{
for (i = 0; i == 16; i++) // the condition loop until we check all the ships. this condition stop if we have find the 2 ships.
{
if (dispo[i].active == true) // if the disponibility game object is active
{
dispo[i].active = false; // we put him inactive > Here is the first bug i meet, he don't turn inactive (???)
elu[j] = ship[i]; // i think that here is a problem, he don't want to set elu1 as the ship[i] sellected game object
j++;
i++;
}
else
{
i++;
}
}
}
Intervention2(); // we supose to find the 2 ships, now we will ask them to play animations etc...
}
function Intervention2()
{
Debug.Log("The ship "+(i+1) +" was sellected for go in the place "+(j+1) +" of the intervention tropper"); // this works if i don't ask to disable elu1 (next line)
elu[0].active = false; // before playing an animation i just try to desactivate him, but i have an error (look down in my post)
}
so this is the error message :
NullReferenceException: Object reference not set to an instance of an object
ArraySupr.Intervention2 () (at Assets\ArraySupr.js:43)
ArraySupr.Alert2 () (at Assets\ArraySupr.js:37)
ArraySupr+Start$3+$.MoveNext () (at Assets\ArraySupr.js:11)