private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Trap") { LiftOffTrap trap = collision.GetComponent <LiftOffTrap>(); if (trap.team != pInput.team) { if (stunned <= 0.0f) { stunned = stunTime; AudioManager.PlayerStunned(); } Destroy(trap.gameObject); } } }
void Update() { if (!pInput.IsActive()) { return; } float hSpeed = this.forwardSpeed; float jStrength = this.jumpStrength; if (stunned > 0.0f) { stunned -= Time.deltaTime; hSpeed = 0; jStrength = 0; } //Jump bool jumped = false; if (this._isWalled) { if (pInput.IsJumping(true)) { float jumpOffDirection = 0; jumped = true; this._jumpCount += 1; jumpOffDirection = (this._lastWallHit.position.x > this.transform.position.x) ? -1f : 1f; _rigidbody2D.velocity = new Vector2(((jumped) ? jumpOffDirection * hSpeed / 2 : this._rigidbody2D.velocity.x), _rigidbody2D.velocity.y + ((jumped) ? jStrength : 0)); } } else if (this._isGrounded || this._jumpCount < JumpCountLimit - 1) { if (pInput.IsJumping(true)) { jumped = true; this._jumpCount += 1; AudioManager.PlayerJumped(); } _rigidbody2D.velocity = new Vector2(((jumped) ? pInput.GetMovement().x *hSpeed / (2 / this._jumpCount) : this._rigidbody2D.velocity.x), _rigidbody2D.velocity.y + ((jumped) ? jStrength : 0)); } //Walk if (this._isGrounded) { _rigidbody2D.velocity = new Vector2(pInput.GetMovement().x *hSpeed, _rigidbody2D.velocity.y + ((jumped) ? jStrength : 0)); } else { if (!this._isWalled) { _rigidbody2D.velocity = new Vector2(pInput.GetMovement().x *hSpeed, _rigidbody2D.velocity.y); } } //Trapping if (pInput.IsTrapping(true)) { LiftOffTrap t = Instantiate(trap, transform.position, Quaternion.identity).GetComponent <LiftOffTrap>(); t.team = pInput.team; } //LookDirection if (pInput.GetMovement().x > 0) { lookDirection.SetTurnLeft(); } else if (pInput.GetMovement().x < 0) { lookDirection.SetTurnRight(); } else { lookDirection.SetNeutral(); } }