- Home /
Question by
Madswint · Jan 28, 2015 at 12:43 PM ·
networkinginstantiatenetworkviewnetwork.instantiate
Getting this error when using Network.Instantiate
The object is not the main asset. Only root objecs of a prefab may be used for Instantiating UnityEngine.Network:Instantiate(Object, Vector3, Quaternion, Int32) SpawnManager:OnGUI() (at Assets/Script/SpawnManager.cs:45)
Here's my script
//27/01/2015 Mads Winther
using UnityEngine;
using System.Collections;
public class SpawnManager : MonoBehaviour {
public GameObject RunnerPlayer;
public GameObject RunnerCamera;
public GameObject DeathPlayer;
public string CurTeam = "";
private bool Dead = true;
public GameObject SpawnPointRunner;
public GameObject SpawnPointDeath;
public int Runners = 0;
public int Death = 0;
public int MaxRunners;
public int MaxDeath ;
public float CenterW;
public float CenterH;
public bool NewRound = false;
// Use this for initialization
void Start () {
CurTeam = "";
CenterW = Screen.width / 2 - 150;
CenterH = Screen.height / 2 - 80;
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
if (CurTeam == "") {
GUI.Box (new Rect (CenterW, CenterH, 300, 160), "Select Team");
if (GUI.Button (new Rect (CenterW + 5, CenterH + 20, 290, 60), "Runner Team")) {
Network.Instantiate (RunnerPlayer, SpawnPointRunner.transform.position, transform.rotation, 0);
Network.Instantiate (RunnerCamera, SpawnPointRunner.transform.position, transform.rotation, 0);
CurTeam = "Runner";
Runners++;
}
if (GUI.Button (new Rect (CenterW + 5, CenterH + 90, 290, 60), "Death Team")) {
Network.Instantiate (DeathPlayer, SpawnPointDeath.transform.position, transform.rotation, 0);
CurTeam = "Death";
Death++;
}
} else
if (NewRound == true) {
Respawn ();
}
}
void OnDisconnectedFromServer(NetworkDisconnection info) {
if (Network.isServer)
Debug.Log("Local server connection disconnected");
else
if (info == NetworkDisconnection.LostConnection)
Debug.Log("Lost connection to the server");
if(CurTeam == "Runner") {
Runners--;
}
if(CurTeam == "Death") {
Death--;
}
else
Debug.Log("Successfully diconnected from the server");
if(CurTeam == "Runner") {
Runners--;
}
if(CurTeam == "Death") {
Death--;
}
}
void Respawn() {
if(CurTeam == "Runner") {
Network.Instantiate (RunnerPlayer, SpawnPointRunner.transform.position,transform.rotation, 0);
Network.Instantiate (RunnerCamera, SpawnPointRunner.transform.position,transform.rotation, 0);
NewRound = false;
Dead = false;
}
if(CurTeam == "Death") {
Network.Instantiate (DeathPlayer, SpawnPointDeath.transform.position,transform.rotation, 0);
NewRound = false;
Dead = false;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613181753im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
networkView.viewID returning same for server and client 2 Answers
Network.Instantiate and NetworkServer.Spawn not working 2 Answers
Network.Instantiate/Destroy vs Instantiate/Destroy on each client using [Command] and [ClientRpc] 1 Answer
Network, Builds wont move 1 Answer
OnNetworkInstantiate is never called 1 Answer