public void Move(float move, bool crouch, bool jump) { if (!crouch) { if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround)) { crouch = true; } } if (m_Grounded || m_AirControl) { if (crouch) { if (!m_wasCrouching) { m_wasCrouching = true; onCrouchEvent.Invoke(true); } move *= m_CrouchSpeed; if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = false; } } else { if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = true; } if (m_wasCrouching) { m_wasCrouching = false; onCrouchEvent.Invoke(false); } } Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y); m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing); if (move > 0 && !m_FacingRight) { Flip(); } else if (move < 0 && m_FacingRight) { Flip(); } } if (m_Grounded && jump) { m_Grounded = false; m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); } }
// Update is called once per frame void OnTriggerEnter() { toggle = !toggle; onToggleChange.Invoke(toggle); SetChildrenTo(toggle); }
void OnMouseDown() { toggle.Invoke(toggled); toggled = !toggled; }