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);
}
}
This script allows the player to move forward and backward using the Vertical
axis and rotate using the Horizontal
axis. The IsOwner
check ensures that only the player who owns the object can control it.