For the Realm Rush project I am working on adding different towers. For that I had to rework my damage system a bit so that I can introduce variables in it. As a start I tried to add a script to my projectile with a damage vallue that should be dealt to the enemy. This kinda worked… because there are multiple enemies things became a little bit weird. So I tried to take another approach and added something to my enemy instead that reads the dmg value of the projectile.
for that I wrote this:
‘’’
{
Damage damage;
EnemyHealth enemyHealth;
void Start()
{
enemyHealth = FindObjectOfType<EnemyHealth>();
}
void OnParticleCollision(GameObject other)
{
Damage damage = FindObjectOfType<Damage>();
enemyHealth.ProcessDamage(damage.amountOfDamage);
}
}
‘’’
with a serialized value on the projectile. It works !!
for now, and i realise that. Because i know as soon as i will introduce different damage scripts and values it will go wrong again. I know that i can fix this in the easy way of making different taggs and let it look for the value via that, but so far we kept being told that working with strings like that is best avoided.
So I am looking for a way to only interact with the object I colided with and get the value out of a scripts that is from that unit or projectile only.
Beside that the even more important question how I best could have found a way for it myself. It is hard for me so far to find a way if i am not sure where to look.
ps. Sorry for the maybe unnecessary side information around my question