I have a piece of code that in the if statement(line 5 below) checks if an GameObject is not null.
Now in the following if statement(line 7 below) it finds a null object reference,
which to me should logically not happen. since it found an object earlier.
Here is the code:
for(int OB = 1; OB < 9; OB = OB +1)
{
GameObject cardSpot = GameObject.Find("EnemySlot"+OB);
EnemyCardSpot Espot = cardSpot.GetComponent<EnemyCardSpot>();
if(Espot.thatCard != null)
{
if(Espot.enemyCard.me.Energy < Espot.enemyCard.me.DataEnergyMax)
{
if(Espot.enemyCard.me.Energy < 0 && Espot.enemyCard.me.Type != "Infantry")
{
Espot.enemyCard.me.Energy = Espot.enemyCard.me.Energy +1;
}
else
{
Espot.enemyCard.me.Energy = Espot.enemyCard.me.DataEnergyMax;
Espot.enemyCard.Active = true;
}
}
else
{
Espot.enemyCard.Active = true;
}
}
}