void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Player")) { knight.TakeDamage(damageAmount); } }
private void OnTriggerEnter2D(Collider2D hitInfo) { playerMovement player = hitInfo.GetComponent <playerMovement>(); if (player != null) { player.TakeDamage(damage); } }
public void Explode() { if (rb != null && canExplode && !hasExploded) { playerMovement pMove = rb.GetComponent <playerMovement>(); if (Vector3.Distance(rb.position, transform.position) < explosionRadius) { Debug.Log(rb.gameObject.name); CharacterController cc = rb.GetComponent <CharacterController>(); cc.enabled = false; } if (pMove != null) { if (Vector3.Distance(rb.position, transform.position) < explosionRadius) { pMove.TakeDamage(explosionDamage); } if (pMove.touchingGround) { pMove.rb = rb; } } Vector3 explosionPosition = new Vector3(transform.position.x, transform.position.y - 0.1f, transform.position.z); if (Vector3.Distance(rb.position, transform.position) < explosionRadius) { rb.AddExplosionForce(force, explosionPosition, explosionRadius); } hasExploded = true; Destroy(gameObject); GameObject explosionEffectObject = Instantiate(explosionEffect, transform.position, Quaternion.identity); //Spawn the explosion particle effect Destroy(explosionEffectObject, 3f); Debug.Log("KABOOM"); } }