private void Die() { gameController.startDay -= StartDay; gameController.stopDay -= StopDay; creatureMovement.Die(); Destroy(gameObject); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.layer == 0 || other.gameObject.layer == 9) { onJumping = false; } if (other.gameObject.layer == 9) { BlockStatus block = other.gameObject.GetComponent <BlockStatus>(); switch (block.type) { case "Jumper": Vector2 jumperVelocity = new Vector2(0, block.value); rigid.AddForce(jumperVelocity, ForceMode2D.Impulse); break; case "DJumper": jumpCount = 0; doubleJump = true; break; case "PortalEnter": Vector3 anotherPortalPos = block.portal.transform.position; Vector3 warpPos = new Vector3(anotherPortalPos.x, anotherPortalPos.y + 2f, anotherPortalPos.z); transform.position = warpPos; break; } } if (other.gameObject.tag == "Creature" && !other.isTrigger && rigid.velocity.y < -4f) { CreatureMovement creature = other.gameObject.GetComponent <CreatureMovement>(); creature.Die(); Vector2 killVelocity = new Vector2(0, 14f); rigid.AddForce(killVelocity, ForceMode2D.Impulse); ScoreManager.setScore(creature.score); } else if (other.gameObject.tag == "Creature" && !other.isTrigger && !(rigid.velocity.y < -4f) && !isUnBeatTime) { Vector2 attackedVelocity = Vector2.zero; if (other.gameObject.transform.position.x > transform.position.x) { attackedVelocity = new Vector2(-2f, 7f); } else { attackedVelocity = new Vector2(2f, 7f); } rigid.AddForce(attackedVelocity, ForceMode2D.Impulse); health--; if (health > 0) { isUnBeatTime = true; StartCoroutine("UnBeatTime"); } } if (other.gameObject.tag == "Fall") { health = 0; } if (other.gameObject.tag == "Coin") { BlockStatus coin = other.gameObject.GetComponent <BlockStatus>(); ScoreManager.setScore((int)coin.value); Destroy(other.gameObject, 0f); } if (other.gameObject.tag == "End") { GameManager.EndGame(); } if (other.gameObject.tag == "Key") { isKey = true; Destroy(key); } if (other.gameObject.tag == "Prison") { if (isKey) { isPrison = false; Destroy(prison); } } if (other.gameObject.tag == "Zinha") { if (isKey) { if (!isPrison) { GameManager.EndGame(); } } } }