private void Jump() { if (GroundChecker.Check(groundCheck)) { _jump = false; _rb.velocity = new Vector2(_rb.velocity.x, jumpForce * 2); } }
private void OnTriggerEnter2D(Collider2D other) { var sc1r = side1Check.Check(); var sc2r = side2Check.Check(); var comparedTag = other.gameObject.CompareTag("Level Tiles"); if (!itemCollectable.IsCollected && splatParent != null && other.gameObject.CompareTag("Level Tiles") && side1Check.Check() && side2Check.Check()) { var splat = Instantiate(splatPrefab, transform); splat.transform.parent = splatParent.transform; if (gameOver) { return; } PreventMovement(); itemCollectable.Reset(); } }
// Update is called once per frame void Update() { if (jumpType == JumpType.Charge) { if (Input.GetKeyDown(KeyCode.Space)) { _jumpTimer.Start(); } if (Input.GetKeyUp(KeyCode.Space)) { if (GroundChecker.Check(groundCheck)) { _jumpTimer.Stop(); _jump = true; } else { _jumpTimer.Stop(); _jumpVelocity = 0; } } } if (jumpType == JumpType.Flat) { if (Input.GetKeyDown(KeyCode.Space)) { _jump = true; } } if (jumpType == JumpType.Hold) { if (GroundChecker.Check(groundCheck) && Input.GetKeyDown(KeyCode.Space)) { _jump = true; jumpTimeCounter = jumpTime; } } if (Input.GetKeyUp(KeyCode.Space)) { jumpTimeCounter = 0; _jump = false; } }
private void Move() { if (GroundChecker.Check(groundCheck)) { _speed = Input.GetKey(KeyCode.LeftShift) ? _player.speed * sprintSpeedMultiplier : _player.speed; } Vector3 targetVelocity = new Vector2((_movement * _speed) * 10f * Time.fixedDeltaTime, _rb.velocity.y); _rb.velocity = Vector3.SmoothDamp( _rb.velocity, targetVelocity, ref _velocity, movementSmoothing); }