- Home /
Only one player for the host but two for the client,
Hello, I recently try the Netcode SDK, i've followed drapperdino tutorial, and when i click on start the game i've created a very simple script in a gameobject called GameManager (object & script). But when i start the game the client see 2 players but the host see only one players. I've added the player prefab (literally a capsule with a camera behind) to Networked Prefab in NetworkManager. And finally i've added a NetworkObject to the Player Prefab. P.S.I don't use the PlayerPrefab option in NetworkManager.
Here is my GameManager.cs
 using System.Collections;
 using System.Collections.Generic;
 using Unity.Netcode;
 using UnityEngine;
 
 public class GameManager : NetworkBehaviour
 {
 
     public GameObject PlayerPrefab;
     public float x1;
     public float x2;
     public float y;
     public float z1;
     public float z2;
 
     void Start()
     {
         Spawn();
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     private void Spawn()
     {
         GameObject SpawnBlock = GameObject.Find("StartLine");
         if (SpawnBlock == null)
         {
             Debug.LogError("Can't find starting line !");
         }
         else
         {
             x2 = (SpawnBlock.transform.localScale.x / 2) - 1;
             x1 = x2 * -1;
             y = SpawnBlock.transform.position.y + 1.5f;
             z2 = (SpawnBlock.transform.localScale.z / 2) - 1;
             z1 = z2 * -1;
             GameObject Player = Instantiate(PlayerPrefab, new Vector3((float)System.Math.Round(Random.Range(x1, x2), 0), y, (float)System.Math.Round(Random.Range(z1, z2), 0)), Quaternion.identity);
             Player.GetComponent<NetworkObject>().Spawn();
             Player.name = "Player_" + PlayerPrefs.GetString("PlayerName");
 
         }
     }
 }
If someone can help me ? Sincerally D.Banache ,Hello, I recently try the Netcode SDK, i've followed drapperdino tutorial, and when i click on start the game i've created a very simple script in a gameobject called GameManager (object & script). But when i start the game the client see 2 players but the host see only one players. I've added the player prefab (literally a capsule with a camera behind) to Networked Prefab in NetworkManager. And finally i've added a NetworkObject to the Player Prefab. P.S.I don't use the PlayerPrefab option in NetworkManager.
Here is my GameManager.cs
 using System.Collections;
 using System.Collections.Generic;
 using Unity.Netcode;
 using UnityEngine;
 
 public class GameManager : NetworkBehaviour
 {
 
     public GameObject PlayerPrefab;
     public float x1;
     public float x2;
     public float y;
     public float z1;
     public float z2;
 
     void Start()
     {
         Spawn();
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     private void Spawn()
     {
         GameObject SpawnBlock = GameObject.Find("StartLine");
         if (SpawnBlock == null)
         {
             Debug.LogError("Can't find starting line !");
         }
         else
         {
             x2 = (SpawnBlock.transform.localScale.x / 2) - 1;
             x1 = x2 * -1;
             y = SpawnBlock.transform.position.y + 1.5f;
             z2 = (SpawnBlock.transform.localScale.z / 2) - 1;
             z1 = z2 * -1;
             GameObject Player = Instantiate(PlayerPrefab, new Vector3((float)System.Math.Round(Random.Range(x1, x2), 0), y, (float)System.Math.Round(Random.Range(z1, z2), 0)), Quaternion.identity);
             Player.GetComponent<NetworkObject>().Spawn();
             Player.name = "Player_" + PlayerPrefs.GetString("PlayerName");
 
         }
     }
 }
 
If someone can help me ?
Sincerally D.BANACHE
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                