void Update() { // cheat if (inputEnabled && Input.GetButtonDown("Cheat")) { if (!cheat) { cheat = true; health = 999; cheatText.SetActive(true); } else { cheat = false; health = 100; cheatText.SetActive(false); } } wasGrounded = isGrounded; isGrounded = ((Physics2D.Raycast(transform.position + -transform.up * 0.1f, -transform.up, filter, results, jumpThreshold)) == 1 || (Physics2D.Raycast(transform.position + transform.right * 0.4f + -transform.up * 0.1f, -transform.up, filter, results, jumpThreshold) == 1) || (Physics2D.Raycast(transform.position + -transform.right * 0.4f + -transform.up * 0.1f, -transform.up, filter, results, jumpThreshold) == 1)); ceilingCheck = collider2d.Raycast(Vector2.up, filter, results, collider2d.bounds.extents.y + collider2d.bounds.extents.y) == 1; rightSideCheck = collider2d.Raycast(Vector2.right, jumpFilter, results, collider2d.bounds.extents.x + 0.1f) == 1; leftSideCheck = collider2d.Raycast(Vector2.left, jumpFilter, results, collider2d.bounds.extents.x + 0.1f) == 1; meleeCheck = Physics2D.Raycast(transform.position + Vector3.up + Vector3.left * 1.2f, transform.right, 2.5f, LayerMask.GetMask("Enemy")); if (rb2D.velocity.y < 0) { rb2D.velocity += Vector2.up * Physics.gravity.y * (1.3f - 1) * Time.deltaTime; } //else if(rb2D.velocity.y > 0 && !Input.GetButton ("Jump" )) // rb2D.velocity += Vector2.up * Physics.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime; if (meleeCheck) { target = meleeCheck.collider.gameObject; if (target.GetComponent <EnemyPatrol>()) { target.transform.GetChild(0).gameObject.SetActive(true); } } else if (target) { if (target.GetComponent <EnemyPatrol>()) { target.transform.GetChild(0).gameObject.SetActive(false); } } if (inputEnabled && inputManager.dash) { if (animator.GetBool("isOnAir") && !animator.GetBool("isGrabbing") && canDash) { StartCoroutine("Dash"); } else if (isGrounded && canSlide) { StartCoroutine("Slide"); } } if ((inputEnabled || (animator.GetBool("isSliding") && !ceilingCheck || isRotSliding)) && inputManager.jump && (isGrounded || animator.GetBool("isGrabbing"))) { if (isGrounded && !isSliding && !isRotSliding) { AudioManager.instance.PlaySound("shouts", transform.position, 0.4f, 0.98f); StartCoroutine(Jump()); animator.SetTrigger("jump"); } else { AudioManager.instance.PlaySound("jumponwall", transform.position, 0.5f); StartCoroutine(Jump()); } inputEnabled = true; if (isFacingRight) { barrelFXSocket.transform.localPosition = barrelFXJumpingPos; } else { barrelFXSocket.transform.localPosition = new Vector3(-barrelFXJumpingPos.x, barrelFXJumpingPos.y, barrelFXJumpingPos.z); } } if (!animator.GetBool("isGrabbing")) { if (isFacingRight && sprite.flipX) { sprite.flipX = false; } else if (!isFacingRight && !sprite.flipX) { sprite.flipX = true; } } groundHit = Physics2D.Raycast(transform.position + Vector3.up * 0.7f + Vector3.left * 0.51f, Vector3.down, 0.5f, LayerMask.GetMask("Default")); axis = Vector3.Cross(-transform.up, -groundHit.normal); if (axis != Vector3.zero && !groundHit.collider.CompareTag("Enemy")) { angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, -groundHit.normal)); transform.RotateAround(axis, angle); inputEnabled = false; animator.SetBool("isSliding", true); isRotSliding = true; rb2D.velocity = Vector2.zero; movement = Vector2.zero; } else if ((!isGrounded && !groundHit) && health != 0 && !animator.GetBool("isGrabbing") && !isDashing) { animator.SetBool("isSliding", false); isRotSliding = false; inputEnabled = true; animator.SetBool("isOnAir", true); transform.rotation = Quaternion.identity; } else if (isRotSliding) { movement = new Vector2(5.5f, -6.7f); } if (inputEnabled && inputManager.fire && !animator.GetBool("isGrabbing")) { if (meleeCheck && !animator.GetCurrentAnimatorStateInfo(0).IsName("Player_Melee") && isGrounded && target.GetComponent <EnemyPatrol>()) { target.GetComponent <EnemyPatrol>().MeleeDeath(); Instantiate(meleeFX, barrelFXSocket.transform); movement = Vector2.zero; animator.SetTrigger("melee"); inputEnabled = false; StartCoroutine(WaitMelee()); } else if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Player_Melee")) { Instantiate(barrelFX, barrelFXSocket.transform); GameObject shot = Instantiate(bullet, barrelFXSocket.transform.position, Quaternion.identity); animator.SetTrigger("fire"); StartCoroutine(FireDelay()); if (isFacingRight) { shot.GetComponent <Bullet>().isRight = true; } } } if (wantToStandUp && !ceilingCheck) { StartCoroutine(StopSliding()); wantToStandUp = false; } if (wasGrounded && !isGrounded && !isRotSliding) { animator.SetBool("isOnAir", true); } else if (isGrounded && !wasGrounded && !isRotSliding) { OnLanding(); } if (!isGrounded && isSliding) { StartCoroutine(StopSliding()); } if (isDashing && animator.GetBool("isGrabbing")) { StartCoroutine(StopDashing()); } if (canControlStellar && inputEnabled && inputManager.changePawn && ((movement.x < 0.1f && movement.x > -0.1f && isGrounded) || animator.GetBool("isGrabbing"))) { mainScript.ChangePawn(2); } if (inputEnabled && inputManager.interact && isOnTrigger && interactableObject.GetComponent <ButtonAction>()) { StartCoroutine(interactableObject.GetComponent <ButtonAction>().OnInteract()); } }
public void teleport() { a.PlaySound("dash"); trail.emitting = true; Vector2 startp = mainCode.trs.position; trail.AddPosition(mainCode.trs.position); mainCode.trs.position += Vector3.right * mainCode.movSen * 1f; tptm = tpCd; Vector2 dir = new Vector2(Mathf.RoundToInt(mainCode.axis), Mathf.RoundToInt(mainCode.ayis)); dir.Normalize(); Vector2 siz = this.gameObject.GetComponent <CapsuleCollider2D>().size; Vector2 ofs = this.gameObject.GetComponent <CapsuleCollider2D>().offset; Vector2 final; GameObject in_portal = Instantiate(Tp, mainCode.trs.position, mainCode.trs.rotation); in_portal.GetComponent <SpriteRenderer>().color = new Color(0.15f, 0.4f, 0.33f, 1); CapsuleCollider2D col = this.gameObject.GetComponent <CapsuleCollider2D>(); List <RaycastHit2D> touchingpoints = new List <RaycastHit2D>(); ContactFilter2D c = new ContactFilter2D(); c.SetLayerMask(LayerMask.GetMask("solid")); if (dir == Vector2.zero) { dir = mainCode.movSen * Vector2.right; } int dest = col.Raycast(dir, c, touchingpoints, teleportRange); if (dest > 0) { Debug.Log(c.IsFilteringLayerMask(touchingpoints[0].transform.gameObject)); final = touchingpoints[0].point - dir; } else { final = (Vector2)mainCode.trs.position + (dir * teleportRange); } trail.AddPosition(final); Debug.DrawLine(mainCode.trs.position, final, Color.red, 5); ext_portal = Instantiate(Tp, final, mainCode.trs.rotation); ext_portal.GetComponent <SpriteRenderer>().color = new Color(0f, 1f, 0.57f, 1); mainCode.flytime = 0; mainCode.trs.position = final; trail.AddPosition(final); if (swordtrail.emitting) { c.SetLayerMask(LayerMask.GetMask("hitable")); col.Raycast(-dir, c, touchingpoints, teleportRange); foreach (RaycastHit2D targ in touchingpoints) { if (targ) { if (targ.collider.gameObject.tag.Equals("hitable")) { var hited = targ.transform.gameObject.GetComponent <CombatEnemy>(); hited.takedamage(mainCode.attackdmg, mainCode.knockback); } if (targ.collider.gameObject.tag.Equals("Boss")) { var hited = targ.collider.gameObject.GetComponent <HitableParts>(); if (hited) { hited.takedamage(mainCode.attackdmg); } else { var bhited = targ.collider.gameObject.GetComponent <InfectedNKBehavior>(); bhited.bossCore.takedamage(mainCode.attackdmg); } } } } } //trail.emitting = false; }