Hello!
I’am trying to learn one of my heroes to make reflect attack.
So hero must return damage when any enemy attacks him.
Hero have property “health”. And when enemy attacks. I make hero.health-=attackDamage.
How I can make reflect attack and return damage?
I don’t know which enemy attack my current hero. But I think that sending with attackDamage reference to enemy is not correct. It will work. But it will be ugly and not so beautiful.
May be I can automatically get object which change property of my hero in GET and SET methods?
Or may be you know other way?)
Hi hromoy,
Maybe try making another variable on your “hero” script that holds a GameObject. Like “var enemyThatIsAttacking : GameObject;”
Then, when you make hero.health -= attackDamage, also make “hero.enemyThatIsAttacking = enemyThatIsAttacking.gameobject;” or something like that.
Then, immediately after that, on your hero script do: “enemyThatIsAttacking.GetComponent(ScriptOnEnemy).health -= attackDamage” as well.
Like you said, somehow you have to have a way of knowing what enemy actually is attacking your hero. It is a bit tricky if you’re learning how to code, but there can be multiple ways of doing the same thing. There is no way to know if a way is the “most elegant” really, other than performance I guess. Just try to get it to work first, and worry about performance later 
Good luck.
Thanks, Velo22
I hope that it is a way to get reference automatically, but it isn’t.
So I use you advice.
Thank you.