internal void OnTriggerEnter2D(Collider2D collision) { ActivatePlatform platform = collision.gameObject.GetComponent <ActivatePlatform>(); if (platform != null) { if (gameObject.tag == "SniperBullet") { Die(); } } }
void FixedUpdate() { //Physics2D.Linecast(gameObject.transform.position, gameObject.transform.position + 5f*Vector3.down) //Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer) grounded = Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer) || Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer) || Physics2D.OverlapCircle(groundCheckR.position, groundRadius, groundLayer); Collider2D plat = null; if (grounded) { if (Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer)) { plat = Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer); } else if (Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer)) { plat = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer); } else if (Physics2D.OverlapCircle(groundCheckR.position, groundRadius, groundLayer)) { plat = Physics2D.OverlapCircle(groundCheckR.position, groundRadius, groundLayer); } } if (plat != null) { ActivatePlatform platActive = plat.gameObject.GetComponent <ActivatePlatform>(); if (platActive && !platActive.isActive) { grounded = false; } } teleported = Physics2D.OverlapCircle(teleportCheckL.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(teleportCheck.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(teleportCheckR.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(groundCheckL.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(groundCheck.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(groundCheckR.position, teleportRadius, teleportLayer) || Physics2D.OverlapCircle(teleportCheckC.position, teleportRadiusCenter, teleportLayer); if (teleported && proceedTeleport) { flash.Play("Flash"); //RocketFuel.value = 1f; //currentFuel = MaxFuel; //obtained from teleport telePlay.MovePlayer(teleportLocation); SoundManager.instance.PlaySingle(tel); rb2d.velocity = new Vector2(0f, 0f); teleported = false; wasInverted = false; if (rb2d.gravityScale < 0) { rb2d.gravityScale *= -1; } grav = 1.0f; _lastSwitch = Time.time - _gravityCoolDown; if (transform.rotation != originalRotation) { transform.rotation = Quaternion.Slerp(transform.rotation, originalRotation, Time.deltaTime * 100f); } checkForRocketGround = true; proceedTeleport = false; } if (grounded) { doubleJump = false; //usedRocket = false; } if (checkForRocketGround) { /* * Collider2D leftOverlap = Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer); * Collider2D middleOverlap = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer); * Collider2D rightOverlap = Physics2D.OverlapCircle(groundCheckR.position, groundRadius, groundLayer); * * if(leftOverlap != null) * { * if(leftOverlap.gameObject != null) * { * if(leftOverlap.gameObject.GetComponent<ActivatePlatform>() != null) * { * * if (leftOverlap.gameObject.GetComponent<ActivatePlatform>().isActive) * { * rocketGrounded = true; * } * * else * { * rocketGrounded = false; * } * * } * * else * { * rocketGrounded = true; * } * * } * } * * else if (middleOverlap != null) * { * if (middleOverlap.gameObject != null) * { * if (middleOverlap.gameObject.GetComponent<ActivatePlatform>() != null) * { * if (middleOverlap.gameObject.GetComponent<ActivatePlatform>().isActive) * { * rocketGrounded = true; * } * * else * { * rocketGrounded = false; * } * } * * else * { * rocketGrounded = true; * } * * } * } * * else if (rightOverlap != null) * { * if (rightOverlap.gameObject != null) * { * if (rightOverlap.gameObject.GetComponent<ActivatePlatform>() != null) * { * if(rightOverlap.gameObject.GetComponent<ActivatePlatform>().isActive) * { * rocketGrounded = true; * } * * else * { * rocketGrounded = false; * } * } * * else * { * rocketGrounded = true; * } * * } * } * */ rocketGrounded = Physics2D.OverlapCircle(groundCheckL.position, groundRadius, groundLayer) || Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer) || Physics2D.OverlapCircle(groundCheckR.position, groundRadius, groundLayer); } if (rocketGrounded) { checkForRocketGround = false; usedRocket = false; rocketGrounded = false; } float move = Input.GetAxis("Horizontal"); rb2d.velocity = new Vector2(move * maxSpeed, rb2d.velocity.y); if (!wasInverted) { if (move > 0 && !facingRight) { Flip(); } else if (move < 0 && facingRight) { Flip(); } } else { if (move < 0 && !facingRight) { Flip(); } else if (move > 0 && facingRight) { Flip(); } } }