void Start() { playerState = GetComponent <PlayerStateController>(); playerState.SetState(PlayerState.Idle); rigidbody = GetComponent <Rigidbody>(); movementSpeed = walkMovementSpeed; facingRight = true; }
void Update() { if (stateController.IsCurrentStateInRange(State.Appear, State.Disappear)) { return; } if (isGrounded || isGuidedJump) { float moveDirection = Input.GetAxis("Horizontal"); playerBody.velocity = new Vector2(moveDirection * runSpeed, playerBody.velocity.y); if (moveDirection == 0) { stateController.SetState(State.Idle); } else if (isGrounded) { stateController.SetState(State.Run); } if ((moveDirection > 0 && !isFacingRight) || (moveDirection < 0 && isFacingRight)) { Flip(); } } if (Controls.IsJumpKeyDown && isJumpAvailable) { StartCoroutine(JumpRoute()); } else if (Controls.IsJumpKeyUp) { StopCoroutine(JumpRoute()); } }
public void Select() { //Turns on the UI ui.gameObject.SetActive(true); UpdatePos(); //Turns off the UI if button no longer held if (!playerStateController.Select) { TowerScriptableObject selectedSegment = GetSelectedSegment(); if (selectedSegment && inventory.ResourceAmount - selectedSegment.Cost >= 0) { inventory.ResourceAmount -= selectedSegment.Cost; selectedSegment.InstantiateConstructionTower(playerStateController); playerStateController.SetState(PlayerStates.BUILDING); } else { playerStateController.SetState(PlayerStates.FREE); } ui.gameObject.SetActive(false); } }