What I am trying to achine is OnParticle collision retrieve a public variable stored on the script called Tower to then subtract that from the current units health which sounds simple in theory just really not sure where I am goind wrong. Collisions and send messages are enabled on the emitter but keep getting a null reference exeception every time the ProcessHit method is called. Any ideas?
Setting the Public variable in the script Tower with the following
public int TowerDamage {get{return towerDamage;}}
The OnParticleCollision Method and Process Hit method below
private void OnParticleCollision(GameObject other)
{
ProcessHit(other);
}
void ProcessHit(GameObject other)
{
int damageToTake = other.GetComponent<Tower>().TowerDamage;
Debug.Log("Damage to take = " + damageToTake);
currentHP -= damageToTake;
if (currentHP <= 0)
{
gameObject.SetActive(false);
enemy.RewardGold();
maxHP += difficultyRamp;
}
}
It seems to be complaining at the “int damageToTake = other.GetComponent().TowerDamage;” line and the debug following is never shown.