Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Mirror;
- using UnityEngine;
- using Cinemachine;
- using UnityEngine.InputSystem;
- public class SimpleNetPlayer : NetworkBehaviour
- {
- //-- player movement --//
- public float playerMoveSpeed = 2.0f;
- Vector2 PlayerMovementInputVector;
- float moveX;
- float moveZ;
- //-- Input Variables --//
- private PlayerInput playerInput;
- private MyInputActions myInputActions;
- // -- Animation --//
- public Animator animator;
- //==== On Start Local Player ====//
- public override void OnStartLocalPlayer()
- {
- //setup Player input
- PlayerInputSetup();
- // Find player camera and tell it to look at this player
- GameObject.Find("PlayerFollowCamera").GetComponent<CinemachineVirtualCamera>().Follow = this.gameObject.transform.GetChild(0).transform;
- Camera.main.transform.SetParent(transform);
- Camera.main.transform.localPosition = new Vector3(0, 0, 0);
- }
- //==== Input Sytem ====//
- public void PlayerInputSetup()
- {
- playerInput = GetComponent<PlayerInput>();
- myInputActions = new MyInputActions();
- myInputActions.Player.Enable();
- }
- //==== Update ====//
- //[Client]
- private void Update()
- {
- if (!isLocalPlayer)
- {
- return;
- }
- PlayerMove();
- }
- //==== Player Move ====//
- public void PlayerMove()
- {
- PlayerMovementInputVector = myInputActions.Player.Move.ReadValue<Vector2>();
- moveX = PlayerMovementInputVector.x * Time.deltaTime * 110.0f;// _input.move.x
- moveZ = PlayerMovementInputVector.y * Time.deltaTime * playerMoveSpeed;//_input.move.y
- transform.Translate(0, 0, moveZ);
- transform.Rotate(0, moveX, 0);
- if (isLocalPlayer)
- {
- animator.SetFloat("Speed", PlayerMovementInputVector.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement