// Start is called before the first frame update void Start() { playerCntrl = player.GetComponent <PlayerController>(); playerMvmnt = player.GetComponent <PlayerMovement>(); playerDrctnl = player.GetComponent <PlayerDirectional>(); keyboadMovement = player.GetComponent <KeyboardMovement>(); }
public PlayerData(PlayerDirectional player) { this.PositionX = player.playerCharacterObject.transform.position.x; this.PositionY = player.playerCharacterObject.transform.position.y; this.PositionZ = player.playerCharacterObject.transform.position.z; this.Died = player.died; this.Speed = player.speed; }
public static void SaveGame(PlayerDirectional player) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/gameData.txt"; FileStream stream = new FileStream(path, FileMode.Create); PlayerData playerData = new PlayerData(player); GameData gameData = new GameData(playerData); formatter.Serialize(stream, gameData); stream.Close(); }
public void PlayerIdle() { _directional = PlayerDirectional.Center; hand.SetActive(false); if (_playerState == PlayerState.Head) { _animator.Play("Guy_idle_head"); } else { _animator.Play("Guy_idle"); } }
public void PlayerMove(Vector3 directional) { if (_directional != PlayerDirectional.Center || _oldPlayerState != _playerState) { switch (_playerState) { case PlayerState.Free: _animator.Play("Guy_run"); hand.SetActive(false); break; case PlayerState.Grabbed: _animator.Play("Guy_run_grabbed"); hand.SetActive(true); break; case PlayerState.Head: _animator.Play("Guy_run_head"); break; case PlayerState.GrabbedAndHead: _animator.Play("Guy_run_head_grabbed"); hand.SetActive(true); break; } } if (directional.magnitude > 0) { directional.Normalize(); if (directional.magnitude != 0) { transform.Translate(directional * (walkSpeed * Time.deltaTime)); var handPos = hand.transform.position; if (directional.x > 0) { _directional = PlayerDirectional.Right; _spriteRenderer.flipX = true; hand.transform.localPosition = new Vector3(-handOffset.x, handOffset.y, handOffset.z); hand.GetComponent <SpriteRenderer>().flipX = true; if (_grabbedItem) { _grabbedItem.transform.localPosition = new Vector3(-itemOffset.x, itemOffset.y, itemOffset.z); hand.GetComponent <SpriteRenderer>().flipX = true; } } else { _directional = PlayerDirectional.Left; _spriteRenderer.flipX = false; hand.transform.localPosition = new Vector3(handOffset.x, handOffset.y, handOffset.z); hand.GetComponent <SpriteRenderer>().flipX = false; if (_grabbedItem) { _grabbedItem.transform.localPosition = new Vector3(itemOffset.x, itemOffset.y, itemOffset.z); hand.GetComponent <SpriteRenderer>().flipX = false; } } var posY = transform.position.y; var posZ = transform.position.z; if (transform.position.x < limitX.x) { transform.position = new Vector3(limitX.x, posY, posZ); } if (transform.position.x > limitX.y) { transform.position = new Vector3(limitX.y, posY, posZ); } } } _oldPlayerState = _playerState; }