Implement player network spawning and position synchronization

This commit is contained in:
2024-08-25 17:43:19 +02:00
parent 6e037b4d06
commit b05cab8288
30 changed files with 689 additions and 26 deletions

View File

@@ -0,0 +1,27 @@
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using Zenject;
public class GameManager : NetworkBehaviour
{
[SerializeField]
[ReadOnly]
[Inject]
private PlayerComponent localPlayer;
public PlayerComponent LocalPlayer {
get { return localPlayer; }
}
public void PlayerSpawnedOnNetwork(PlayerComponent player)
{
if (player.IsLocalPlayer)
{
player.Teleport(localPlayer.Position, localPlayer.Rotation);
localPlayer.DestroyWithDependencies();
localPlayer = player;
}
}
}