- Create a new C# script named
PlayerController
and attach it to the player prefab. - Implement basic movement logic:
using UnityEngine;
using Unity.Netcode;
public class PlayerController : NetworkBehaviour
{
public float moveSpeed = 5f;
public float rotateSpeed = 200f;
void Update()
{
if (!IsOwner) return; // Only allow control by the local player
float move = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
float rotate = Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;
transform.Translate(0, 0, move);
transform.Rotate(0, rotate, 0);
}
}