/// <inheritdoc /> public override void Die() { base.Die(); Walker.IsMoveInputBlocked = true; Text restartText = GameObject.Find("RestartText").GetComponent <Text>(); if (restartText) { restartText.enabled = true; } Debug.Log(gameObject.name + " died"); Anim.SetBool("Dead", true); //disable all scriptstry GrappleHook grappleHook = GetComponent <GrappleHook>(); if (grappleHook) { grappleHook.EndGrapple(); } SpriteRenderer.color = Color.white; // disabling scripts (super buggy) try { Destroy(GetComponent <GrappleHook>()); Destroy(GetComponent <PlayerAttack>()); // Destroy(GetComponent<PlayerMove>()); Destroy(GetComponent <Shooter>()); // Destroy(GetComponent<Health>()); } catch (Exception e) { Debug.LogError("Caught: " + e); } foreach (MonoBehaviour script in GetComponents <MonoBehaviour>()) { try { script.enabled = false; // Destroy(script); } catch (Exception e) { Debug.LogError("Caught: " + e); } } }
/// <summary> /// If you want to modify any movements or Rigidbody forces/velocity do that here, /// otherwise your changes will be immediately overriden by this method as the velocity is modified directly. /// </summary> private void Move() { if (IsMoveInputBlocked) { print(name + ": Input is blocked, not gonna move"); Movement = 0; return; } if (Anim.GetBool("DashAttack")) { return; } if (control_AirControl || Grounded) { Movement = MovementInput.x * MoveSpeed * Momentum; } // If reached jump peak if (Mathf.Approximately(Rb.velocity.y, 0) && !Grounded) { } // If on the wall if (!Grounded && WallCheck && Movement * Mathf.Sign(FacingSign) > 0 && !Anim.GetBool("Slamming")) { if (Rb.velocity.y < 0) { m_hasDoubleJump = true; // limit wallslide speed if (Rb.velocity.y < -WallSlideSpeedMax) { Rb.velocity = new Vector2(Rb.velocity.x, -WallSlideSpeedMax); } } } if (Grounded && Anim.GetBool("Slamming")) // Stop moving on slam landing { Movement = 0; Anim.SetBool("Slamming", false); } // TODO: on jump buttonUp, if(!m_Jump && Grounded) set rb Y velocity to zero 0 // Move horizontally if (Mathf.Abs(Movement) > 0.05f) { Rb.velocity = /*grapple.m_Flying? Vector2.zero:*/ new Vector2(Movement, Rb.velocity.y); } if (WallCheck) { m_hasDoubleJump = true; } //When to jump if (ToJump) { if (m_grapple.Flying) { m_grapple.EndGrapple(); } if (Grounded) { LastGroundSpeed = Movement; //Updating lastGroundSpeed Jump(); } else if (WallCheck) { //If jumping and on the wall: // NOTE: the player has to be facing the wall to wallslide/walljump Debug.Log("Jump off wall"); Rb.AddForce(Vector2.right * -FacingSign * m_walljumpForce * JumpForce * Rb.mass, ForceMode2D.Impulse); Jump(); Flip(); ToJump = false; } else if (m_controlPlayerCanDoubleJump && m_hasDoubleJump) { // Double jump // Resets vertical speed before doubleJump (prevents glitchy jumping) Rb.velocity = new Vector2(Rb.velocity.x, 0); print("Double jump"); // if grappling, then the player gets an extra jump, otherwise mark that the doubleJump has been used if (!m_grapple.Flying) { m_hasDoubleJump = false; } Jump(); } } if (!WallCheck) { ModifyGravity(); } }