Comment on page
Network Player
- This Character will be controlled by Player.

- After installing, you can drag her Prefabs into scene 2_game
- Then Unpack Completele the prefab, remove Acquire Chan Controller.

- Add new scripts that support Network: Network Object, Network Transform and Network Rigidbody.

- Animator also needs a Network Animator.

- The class Network Char Controller has been modified from Acquire Chan Controller.
- It includes references to NetworkObject and PlayerData.
- And controls the character's movements from Server Side.
NetworkCharController.cs
3KB
Text
- What Player Data does is get Player Input and send to Server

using Unity.Netcode;
using UnityEngine;
public class PlayerData : NetworkBehaviour
{
public NetworkVariable<float> horizontal = new(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<float> vertical = new(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<bool> isRun = new(false, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
private void Update()
{
this.OwnerUpdateInput();
}
protected virtual void OwnerUpdateInput()
{
if (!this.IsOwner) return;
this.horizontal.Value = Input.GetAxis("Horizontal");
this.vertical.Value = Input.GetAxis("Vertical");
this.isRun.Value = Input.GetKey(KeyCode.LeftShift);
}
}
- That concludes the steps needed to have a Basic Network Player.
Last modified 3mo ago