- Home /
GameObject not appearing
Hi, i've been working on a risk type game. I have a gameobject pool too. The thing is that when I try to move an army from one point to another, I extract a gameobject from the pool (set it to active), and then calculate the vector3 it needs to reach its destination so i can make transform.position+=vector/10 -so that it travels in bits. The only problem is that, the object i extract from the pool is active according to activeself, the position changes correctly, but the gameobject does not appear onscreen.
Some code related to the issue: Related to moving the gameobject
private Vector3 getDirection (Casilla destino){
return destino.GetPosition () - army.transform.position;
}
public void move(Casilla destino){
Vector3 direction = getDirection (destino);
Debug.Log (direction);
for (int i = 0; i < 10; i++) {
army.transform.position += direction / 10;
this.wait (0.1f);
}
}
private void wait(float time){
do{
time -= Time.deltaTime;
}while(time > 0);
}
I have three types of soldiers, therefore my pool consists on 3 lists of objects all of which have activeself = false unless i instantiate them, here's the code to do so:
public void instantiate(int units, Tile position){
this.units = units;
switch (units) {
case 0:
return;
case 1:
case 2:
army = main_behavior.mypool.getFromPool(1);
break;
case 3:
case 4:
army = main_behavior.mypool.getFromPool(2);
break;
case 5:
default:
army = main_behavior.mypool.getFromPool(3);
break;
}
if (instantiated() == false)
return;
army.transform.position = position.transform.position;
army.SetActive (true);
}
public void deinstantiate(){
army.SetActive (false);
}
Finally, when i move the character, i do this:
temporal = movable ();
temporal.move (me);
temporal.deinstantiate ();
Where movable is:
Army myarmy = new Army ();
myarmy.instantiate (1,origin);
return myarmy;
I've been looking into it for three days and i don't quite get how to fix this. Any idea? Thanks in advance