- Home /
Question by
CharLo0910 · Jan 31 at 10:22 AM ·
collider
Calling the function from Collied Object
I am making a game such as tower defendin. However I am stuckwhile i ammaking the systemof attack. And this is the hero character detecting enemy.
void OnCollisionEnter2D(Collision2D collision)
{
print(collision.gameObject.name);
if (collision.gameObject.tag == "Enemy")
{
var myScript : MyScript = other.gameObject.GetComponent(MyScript);
myScript.GetComponent<enemyMovement>().getDamage(heroAtt);
}
}
And i am going to call the collied object which is the fuction for getting attack
void getDamage(int AttackGot) => selfHP = selfHP - (AttackGot - enemyDef);
I wanna knw how to call the collied object function
Comment
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
"Show GUITexture within distance" issue 0 Answers
OnCollisionEnter2D is not detecting collisions. 2 Answers
Find closest point of one object 3 Answers
Collider/contact functions on 2d game. 2 Answers