Implement player network spawning and position synchronization
This commit is contained in:
27
Assets/Scripts/Managers/GameManager.cs
Normal file
27
Assets/Scripts/Managers/GameManager.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user