private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == MyTags.BULLET_TAG) { if (tag == MyTags.BEETLE_TAG) { anim.Play("Stunned"); canMove = false; myBody.velocity = new Vector2(0, 0); StartCoroutine(Dead(0.4f)); CoinScript.addScore(); } else if (tag == MyTags.SNAIL_TAG) { if (!stunned) { anim.Play("Stunned"); canMove = false; stunned = true; myBody.velocity = new Vector2(0, 0); CoinScript.addScore(); } else { gameObject.SetActive(false); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == MyTags.BULLET_TAG) { anim.Play("BirdDead"); GetComponent <BoxCollider2D>().isTrigger = true; myBody.bodyType = RigidbodyType2D.Dynamic; canMove = false; StartCoroutine(BirdDead()); CoinScript.addScore(); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == MyTags.BULLET_TAG) { anim.Play("SpiderDead"); myBody.bodyType = RigidbodyType2D.Dynamic; CoinScript.addScore(); StartCoroutine(SpiderDead()); StopCoroutine(coroutine_Name); } if (collision.tag == MyTags.PLAYER_TAG) { collision.GetComponent <PlayerDamage>().DealDamage(); } }
void CheckForCollision() { RaycastHit2D hit = Physics2D.Raycast(bottom_Collision.position, Vector2.down, 0.1f, playerLayer); if (activeBlock) { if (hit) { if (hit.collider.gameObject.tag == MyTags.PLAYER_TAG) { audioManager.Play(); //increase score CoinScript.addScore(); activeBlock = false; //change block anim.Play("BlockCollected"); startAnim = true; } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (canDamage) { if (collision.tag == MyTags.BULLET_TAG) { health--; CoinScript.addScore(); canDamage = false; if (health == 0) { GetComponent <BossScript>().DeactivateBoss(); anim.Play("BossDead"); Invoke("BossGoneNew", 2f); // 2 ways to solve this - IEnumerator or Invoke //StartCoroutine(BossGone()); } StartCoroutine(WaitForDamage()); } } }
void CheckCollision() { RaycastHit2D leftHit = Physics2D.Raycast(left_Collision.position, Vector2.left, 0.1f, playerLayer); RaycastHit2D rightHit = Physics2D.Raycast(right_Collision.position, Vector2.right, 0.1f, playerLayer); Collider2D topHit = Physics2D.OverlapCircle(top_Collision.position, 0.3f, playerLayer); if (topHit != null) { if (topHit.gameObject.tag == MyTags.PLAYER_TAG) { if (!stunned) { // Bounce off player when snail is stunned topHit.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(topHit.gameObject.GetComponent <Rigidbody2D>().velocity.x, 7f); canMove = false; myBody.velocity = new Vector2(0, 0); anim.Play("Stunned"); stunned = true; if (tag == MyTags.BEETLE_TAG) { //anim.Play("Stunned"); StartCoroutine(Dead(0.5f)); CoinScript.addScore(); } } else { if (tag != MyTags.BEETLE_TAG) { myBody.velocity = new Vector2(15f, myBody.velocity.y); StartCoroutine(Dead(3f)); CoinScript.addScore(); } } } } if (leftHit) { if (leftHit.collider.gameObject.tag == MyTags.PLAYER_TAG) { if (!stunned) { //Apply damage to player leftHit.collider.gameObject.GetComponent <PlayerDamage>().DealDamage(); } else { if (tag != MyTags.BEETLE_TAG) { myBody.velocity = new Vector2(15f, myBody.velocity.y); StartCoroutine(Dead(3f)); CoinScript.addScore(); } } } } if (rightHit) { if (rightHit.collider.gameObject.tag == MyTags.PLAYER_TAG) { if (!stunned) { //Apply damage to player rightHit.collider.gameObject.GetComponent <PlayerDamage>().DealDamage(); } else { if (tag != MyTags.BEETLE_TAG) { myBody.velocity = new Vector2(-15f, myBody.velocity.y); StartCoroutine(Dead(3f)); CoinScript.addScore(); } } } } // Testing if we don't detect collision if (!Physics2D.Raycast(down_Collision.position, Vector2.down, 0.2f, groundLayer)) { ChangeDirection(); } }