void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { GameObject p = collision.gameObject; player = p.GetComponent <WarlockJ>(); players.Add(player); var myX = gameObject.transform.position.x; var myY = gameObject.transform.position.y; var otherX = collision.transform.position.x; var otherY = collision.transform.position.y; var x = Mathf.Abs(myX - otherX); var y = Mathf.Abs(myY - otherY); var difference = x + y; //PushBack Enemy Warlock if (difference > .1) { var magnitude = 300; var force = transform.position - collision.transform.position; force = -force.normalized; collision.gameObject.GetComponent <Rigidbody2D>().AddForce(force * magnitude); } player.updateHealth(10); } }
void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { GameObject explosion = Instantiate(Explosion, transform.position, Quaternion.identity) as GameObject; Destroy(explosion, 1.0f); GameObject p = collision.gameObject; player = p.GetComponent <WarlockJ>(); player.updateHealth(10f); player.hit(); Destroy(this.gameObject); //Push the player var magnitude = 300; var force = transform.position - collision.transform.position; force = -force.normalized; collision.gameObject.GetComponent <Rigidbody2D>().AddForce(force * magnitude); } else if (collision.tag == "Spell") { print("fbcollision"); GameObject explosion = Instantiate(Explosion, transform.position, Quaternion.identity) as GameObject; Destroy(explosion, 1.0f); Destroy(this.gameObject); } }