// Start is called before the first frame update void Start() { lockOnList = new List <GameObject>(); walkState = new PlayerWalkState(this.gameObject, this, keyconfig, arm, gun); standState = new PlayerStandState(this.gameObject, this, keyconfig, arm, gun); rollState = new PlayerRollState(this.gameObject, this, keyconfig); rollState.particle = dustParticle; hitboxes = GetComponentsInChildren <Collider2D>(); Initialize(startState: standState); }
private void UpdateGround() { Vector3 colSize = model.GetComponent <BoxCollider>().size; bool touchingGround = Physics.CheckBox(groundTransform.position, new Vector3(colSize.x / 2, groundHeight / 2, colSize.z / 2), transform.rotation, groundLayers); switch (moveState) { case PlayerMoveState.JUMP: if (rb.velocity.y < 0) { moveState = PlayerMoveState.FALLING; } break; case PlayerMoveState.FALLING: if (touchingGround || rb.velocity.y >= 0) { moveState = PlayerMoveState.IDLE; } break; default: if (!touchingGround) { moveState = PlayerMoveState.FALLING; } break; } switch (standState) { case PlayerStandState.GROUND: if (!touchingGround) { standState = PlayerStandState.AIR; } break; case PlayerStandState.AIR: if (touchingGround) { standState = PlayerStandState.GROUND; } break; } }
private PlayerState GetState(PlayerStateEnum _pse, params object[] _args) { PlayerState _ret = null; switch (_pse) { case PlayerStateEnum.Stand: _ret = new PlayerStandState(gameObject); _ret.Reset(); break; case PlayerStateEnum.Walk: Vector2 _walkDir = (Vector2)_args[0]; PlayerWalkState _pws = new PlayerWalkState(gameObject); _pws.Dir = _walkDir; _ret = _pws; break; case PlayerStateEnum.Run: Vector2 _runDir = (Vector2)_args[0]; PlayerRunState _prs = new PlayerRunState(gameObject); _prs.Dir = _runDir; _ret = _prs; break; default: break; } if (_ret == null) { MyLogger.Error("RoleControl", "{0} state don't have a creator!", _pse); return(_ret); } else { return(_ret); } }