private void Start() { Anim = GetComponent <Animator>(); InputHandler = GetComponent <PlayerInputHandler>(); RB = GetComponent <Rigidbody2D>(); DashDirectionIndicator = transform.Find("DashDirectionIndicator"); MovementCollider = GetComponent <BoxCollider2D>(); Inventory = GetComponent <PlayerInventory>(); FacingDirection = 1; PrimaryAttackState.SetWeapon(Inventory.weapons[(int)CombatInputs.primary]); //SecondaryAttackState.SetWeapon(Inventory.weapons[(int)CombatInputs.primary]); StateMachine.Initialize(IdleState); }
private void Start() { playtime = 0; pData = GetComponent <PlayerData>(); if (File.Exists(selectedProfilePath)) { selectedProfile = File.ReadAllText(selectedProfilePath); saveDataPath += selectedProfile + ".json"; if (File.Exists(saveDataPath)) { string json = File.ReadAllText(saveDataPath); var dto = JsonConvert.DeserializeObject <PlayerDTO>(json); pData.serializeData = dto.playerSerializeData; playtime = dto.Playtime; if (pData.HasCheckPoint) { transform.position = new Vector2(pData.PosX, pData.PosY); } } } pInput = new PlayerInput(pData); spriteRenderer = GetComponent <SpriteRenderer>(); audioSource = GetComponent <AudioSource>(); #region Initialize States IdleState = new IdleState(this, pInput, pData, "Idle_Animation"); RunningState = new RunningState(this, pInput, pData, "Running_Animation"); FallingState = new FallingState(this, pInput, pData, "Falling_Animation"); JumpState = new JumpState(this, pInput, pData, "Jump_Animation"); StartFallingState = new StartFallingState(this, pInput, pData, "Start_Falling_Animation"); WallSlideState = new WallSlideState(this, pInput, pData, "Wall_slide"); DashingState = new DashingState(this, pInput, pData, "Dash_Animation"); PrimaryAttackState = new PrimaryAttackState(this, pInput, pData, "Left_swing_attack"); GroundedSecondaryAttackState = new GroundedSecondaryAttackState(this, pInput, pData, "Right_swing_attack"); GroundedDownwardAttackState = new GroundedDownwardAttackState(this, pInput, pData, "Downward");; DeathState = new DeathState(this, pInput, pData, "Death_Animation"); CheckPointState = new CheckPointState(this, pInput, pData, "CheckPoint_Animation"); WallJumpState = new WallJumpState(this, pInput, pData, "Jump_Animation"); currentState = IdleState; #endregion Initialize States }