private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { Instantiate(particlePrefab, playerTarget.transform.position, Quaternion.identity); if (!collision.gameObject.GetComponent <Transform>().GetChild(12).gameObject.activeSelf) { playerTarget.GetComponent <Transform>().GetChild(12).gameObject.SetActive(true); Destroy(this.gameObject); } else if (collision.gameObject.GetComponent <Transform>().GetChild(12).gameObject.activeSelf) { playerTarget.GetComponent <Transform>().GetChild(12).gameObject.SetActive(true); Destroy(this.gameObject); } } }
void OnTriggerEnter2D(Collider2D collider) { switch (collider.tag) { case "mana": character.collectOneMana(10); Destroy(collider.gameObject); break; case "rock": character.GetComponent <Animator> ().Play("Trip", 0, 0); character.GetComponent <Rigidbody2D> ().velocity = new Vector2(character.GetComponent <Rigidbody2D> ().velocity.x * .85f, character.GetComponent <Rigidbody2D> ().velocity.y); Destroy(collider.gameObject); StartCoroutine(hitTheDoor()); break; case "door": character.GetComponent <Animator> ().Play("Giddy", 0, 0); character.GetComponent <Rigidbody2D> ().velocity = new Vector2(character.GetComponent <Rigidbody2D> ().velocity.x * .35f, character.GetComponent <Rigidbody2D> ().velocity.y); Destroy(collider.gameObject); StartCoroutine(hitTheDoor()); break; } }