void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "LEND" || col.gameObject.tag == "BLOCK_BREAKABLE" || col.gameObject.tag == "ENERMY1" || col.gameObject.tag == "ENERMY2" || col.gameObject.tag == "ENERMY3" || col.gameObject.tag == "ITEMBOX" || col.gameObject.tag == "PIPE") { float objH = col.gameObject.transform.localScale.y / 2f; if (transform.localPosition.y > col.gameObject.transform.localPosition.y + objH) { prevBallPosY = transform.localPosition.y; changeUp = 1; } else if (transform.localPosition.y < col.gameObject.transform.localPosition.y - objH) { changeUp = -1; } else if (transform.localPosition.y > col.gameObject.transform.localPosition.y - objH && transform.localPosition.y < col.gameObject.transform.localPosition.y + objH) { isHit = true; ani.Play("hit"); StartCoroutine("destroyFireBall", .2f); } if (col.gameObject.tag == "ENERMY1" || col.gameObject.tag == "ENERMY2" || col.gameObject.tag == "ENERMY3") { isHit = true; EHitEngin hitEnermy = col.gameObject.GetComponent <EHitEngin>(); if (hitEnermy.energy == 2) { hitEnermy.hit(); } hitEnermy.hit(); ani.Play("hit"); StartCoroutine("destroyFireBall", .2f); } } }
void OnControllerColliderHit(ControllerColliderHit hit) { if (!isDie) { CharacterController controller = GetComponent <CharacterController>(); if (blockHitFlag && hit.collider.tag == "BLOCK_BREAKABLE") { if (controller.collisionFlags == CollisionFlags.Above) { if (!isBounce && controller.velocity.y > 0f) { DestroyObject(hit.collider.gameObject); isBounce = true; blockHitFlag = false; } } } if (hit.collider.tag == "FINISH") { finishObject = hit.collider.gameObject; Finished fo = finishObject.transform.parent.GetComponent <Finished>(); fo.upFlag(); isFinish = true; } if (hit.collider.tag == "ITEMBOX") { if (controller.collisionFlags == CollisionFlags.Above) { if (!isBounce && controller.velocity.y > 0f) { isBounce = true; ItemBox ibox = hit.collider.gameObject.GetComponent <ItemBox>(); ibox.hit(); } } } if (!superMode) { if (hit.collider.tag == "ENERMY1") { if (gameObject.transform.localPosition.y - gameObject.transform.localScale.y / 2 > hit.collider.gameObject.transform.localPosition.y) { isRiversBounce = true; EHitEngin hitEnermy = hit.collider.gameObject.GetComponent <EHitEngin>(); hitEnermy.hit(); } else { playerDie(hit.collider.gameObject); } } else if (hit.collider.tag == "ENERMY2") { if (gameObject.transform.localPosition.y - gameObject.transform.localScale.y / 2 > hit.collider.gameObject.transform.localPosition.y) { isRiversBounce = true; EHitEngin hitEnermy = hit.collider.gameObject.GetComponent <EHitEngin>(); hitEnermy.hit(); } else { playerDie(hit.collider.gameObject); } } else if (hit.collider.tag == "ENERMY3") { playerDie(hit.collider.gameObject); } } } }