I’m starting as a host. The prefab with the player will spawn well, and his management works with a bang. But when I still connect as a client, it also works, but the movement of the client player seems to be blocked, although I output logs and they work, and the object itself remains in place. If you turn off Network Transform on the client, the management on the client starts working, but it does not synchronize accordingly.
Scripts for player prefab:
public class PlayerMovement : NetworkBehaviour
{
CharacterController characterController;
public Transform cameraTransform;
float pitch = 0f;
// Start is called before the first frame update
public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
public void Start()
{
if (!IsLocalPlayer) {
cameraTransform.GetComponent<AudioListener>().enabled = false;
cameraTransform.GetComponent<Camera>().enabled = false;
transform.GetComponent<PlayerMovement>().enabled = false;
}
else {
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
}
}
// Update is called once per frame
void Update()
{
if (IsLocalPlayer) {
MovePlayer();
Look();
}
}
void MovePlayer() {
Debug.Log("Двигаем игрока! Горизонталь: " + Input.GetAxis("Horizontal") + "Вертикаль: " + Input.GetAxis("Vertical"));
Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical") );
move = Vector3.ClampMagnitude(move, 1f);
move = transform.TransformDirection(move);
characterController.SimpleMove(move * 5f);
}
void Look() {
float mouseX = Input.GetAxis("Mouse X") * 3f;
transform.Rotate(0,mouseX,0);
pitch -= Input.GetAxis("Mouse Y") * 3f;
pitch = Mathf.Clamp(pitch, -45f, 45f);
cameraTransform.localRotation = Quaternion.Euler(pitch,0,0);
}