Not able to instantiate an object on the Client using [Command] UNET
Hi I just have a problem with UNET and I've been stuck on for quiet a while now . Here is what I want. I want the host and the client to be able to instantiate an object
public void objectPlacement() {
if (isLocalPlayer) {
if (Input.GetKeyUp(KeyCode.E))
{
Debug.Log("InsideKeyCodeE");
placedObstaclesCounter++;
Debug.Log ("placedObstaclesCounter");
Debug.Log (playersObstacles.Length);
if (placedObstaclesCounter < playersObstacles.Length)
{
Debug.Log("InsidePlace");
CmdGenerateObstacles ();
Debug.Log("InsidePlace222");
}
else
{
Debug.Log("Player1'sobstacleplacementisdone!");
//lane.transform.position=endPosition.transform.position;
//this.gameObject.SetActive(false);
}
//}
}
}
}
[Command]
public void CmdGenerateObstacles ()
{
Debug.Log("InNetworkSpawn");
GameObject prefab = playersObstacles [placedObstaclesCounter];
spawnPosition = GameObject.Find (thisPlayerName).transform;
GameObject newObstacle = Instantiate (prefab, spawnPosition.position,Quaternion.identity) as GameObject;
movingObstacle = newObstacle;
NetworkServer.Spawn (newObstacle);
newObstacle.transform.parent = localPlayerPlane.transform;
}
The host is successfully able to spawn an object and works fine , but nothing happens when I try to run it on the client . I have localplayerautority set and all the prefabs have network identity and are set as spoonable objects in network manager . Any help would be greatly appreciated
Your answer
Follow this Question
Related Questions
NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1] 0 Answers
Networking concept and spawning questions 1 Answer
how to spawn a player prefab on a server 0 Answers
Lerping to Smooth Network Movement 0 Answers
Network Soccer Ball Position jitter, sending transform position late? 0 Answers