Here is my code:
protected void TerrainOn(Transform clop)
{
MediumTank tank = currentUnit;
Collider[] colliderList = Physics.OverlapSphere(clop.position, 0.5f);
if (colliderList.Length != 0)
{
switch (colliderList[0].tag)
{
case "town":
GameObject townhexon = GameObject.Find("townHex");
tank.CurrentDefence = tank.InitialDefence + townhexon.GetComponent<Town>().town.VehDefence;
break;
case "plains":
GameObject plainsHexOn = GameObject.Find("plainsHex");
tank.CurrentDefence = tank.InitialDefence + plainsHexOn.GetComponent<Plains>().plains.VehDefence;
break;
}
}
}
Unity throws a null reference exception saying that clop
is not set to an instance of an object on line 4 when I try to execute TerrainOn()
, but clop
is definitely set to a valid transform in the inspector.