To make enemy chase me when i hit them with my projectile i set weapon range equal to enemies chasedistance when projectile hits them. It works fine but i get an object reference not set to an instance of an object error.
In my projectile script i added this code:
float weaponRange = player.GetComponent(Fighter)().GetRange();
other.GetComponent(AIController)().SetChaseDistance(weaponRange);
it points to the second line.
in the fighter script i added a function to get the range:
public float GetRange()
{
return currentWeapon.GetRange();
}
in the aicontroller script i added this function to set the chasedistance:
public void SetChaseDistance(float weaponRange)
{
chaseDistance = weaponRange;
}
any idea whats going on here?