using Mirror; using Player.States; using StateMachine; using UnityEngine; namespace Player { public class Player : MonoBehaviour { public float walkSpeed = 400f; public float runSpeed = 1200f; public float jumpForce = 160f; public float groundCheckRadius = 0.14f; public Transform groundCheck; public LayerMask groundLayer; public Animator animator; public readonly StateMachine StateMachine = new StateMachine(); public GameObject laptopPrefab; [HideInInspector] public Rigidbody playerRigidbody; public bool isGrounded; [HideInInspector] public Vector3 moveDirection; private float _originalHeight; void Start() { playerRigidbody = GetComponent(); StateMachine.Add(new Walk(this)); StateMachine.Add(new Run(this)); StateMachine.Add(new Jump(this)); StateMachine.Add(new MenuState(this)); StateMachine.SetCurrentState(PlayerState.Walk); } void Update() { isGrounded = Physics.CheckSphere(groundCheck.position, groundCheckRadius, groundLayer); moveDirection = (transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical")).normalized; animator.SetFloat("x", Input.GetAxis("Horizontal")); animator.SetFloat("y", Input.GetAxis("Vertical")); if (isGrounded && Input.GetButtonDown("Jump")) { StateMachine.SetCurrentState(PlayerState.Jump); } if (Input.GetKeyDown(KeyCode.Escape) && StateMachine.GetCurrentState().ID != PlayerState.Menu) { StateMachine.SetCurrentState(PlayerState.Menu); } StateMachine.Update(); } void FixedUpdate() { StateMachine.FixedUpdate(); } void OnDrawGizmosSelected() { if (groundCheck != null) { Gizmos.color = Color.red; Gizmos.DrawWireSphere(groundCheck.position, groundCheckRadius); } } private GameObject _laptopInstance; public void OpenMenu() { Vector3 spawnPosition = transform.position + transform.up * 8f + transform.forward * 5f; _laptopInstance = Instantiate(laptopPrefab, spawnPosition, Quaternion.identity); _laptopInstance.transform.SetParent(transform); Debug.Log("Open menu"); Debug.Log(_laptopInstance.transform.position); } public void CloseMenu() { Destroy(_laptopInstance); Debug.Log("DESTROY"); } } }