Code:
player.cs
private void OnCollisionEnter2D(Collision2D otherObject) {
if(otherObject.transform.tag.Equals("Enemy") && playerRB.velocity.y < 0){
// stomp or step over the enemy
otherObject.transform.localScale = new Vector2(1, -1);
otherObject.gameObject.GetComponent<BoxCollider2D>().enabled = false;
if(otherObject.gameObject.GetComponent<EnemyAI>() != null){
otherObject.gameObject.GetComponent<EnemyAI>().enabled = false;
}
//eliminate enemy
Destroy(otherObject.gameObject, 2.0f);
//bounce effect
playerRB.velocity = new Vector2(playerRB.velocity.x, jumpHeight - 2);
}else if(otherObject.transform.tag.Equals("Obstacle")){
PlayAudio(1);
}else if(otherObject.transform.tag.Equals("Enemy")) {
PlayAudio(2);
SceneManager.LoadScene("GameOverScene");
}
}
No comments:
Post a Comment