//Method for destroying(unused) void OnCollisionEnter2D(Collision2D collider) { Projectile proj = collider.gameObject.GetComponent <Projectile>(); EnemyProj enemyProj = collider.gameObject.GetComponent <EnemyProj>(); //Mario player = collider.gameObject.GetComponent<Mario>(); if (enemyProj) { enemyProj.Hit(); } else if (proj) { health -= proj.getDamage(); AudioSource.PlayClipAtPoint(enemyHit, transform.position); proj.Hit(); // The missile is destroyed upon collision with our ship. if (health <= 0) { // We call the Die() method; Die(); } } /*else if (enemyProj) * { * enemyProj.Hit(); * }*/ }
void OnCollisionEnter2D(Collision2D collider) { //We find any enemies in the scene //Cactus enemy = collider.gameObject.GetComponent<Cactus>(); MovingEnemy movEnemy = collider.gameObject.GetComponent <MovingEnemy>(); EnemyProj enemyproj = collider.gameObject.GetComponent <EnemyProj>(); //If the player collides with an enemy, the enemy reduces player's health by its own damage //If player's health is 0, the player dies /*if (enemy) * { * health -= enemy.getDamage(); * if (health <= 0) * { * Die(); * } * }*/ //If the player touches an enemy, he receives damage if (movEnemy) { AudioSource.PlayClipAtPoint(hit, transform.position); //healthKeeper.Damages(movEnemy.getDamage()); health -= movEnemy.getDamage(); if (health <= 0) { Die(); } } //Also receives damage when touching a moving enemy else if (enemyproj) { health -= enemyproj.getDamage(); AudioSource.PlayClipAtPoint(hit, transform.position); enemyproj.Hit(); // The missile is destroyed upon collision with our object. if (health <= 0) { // We call the Die() method; Die(); } } else { //Debug.Log("Floor"); //When player collides with floor, the jump animation stops //This is because I dont know how to stop that animation anim.SetBool("isJumping", false); } }