I am really sorry for asking this here, but I can’t find the error in my code for some time now. I get this error when somebody respawns(both the server host and client)
This is the error that I get:
NullReferenceException: Object reference not set to an instance of an object
Spawning.Respawn () (at Assets/Scripts/Spawning.cs:47)
This is Spawning.cs:
using UnityEngine;
using System.Collections;
public class Spawning : MonoBehaviour {
private bool hasSpawned = false;
GameObject[] spawnPoints;
static public GameObject player;
private int RN;
void Start(){
if(!networkView.isMine){
enabled = false;
}
else{
spawnPoints = GameObject.FindGameObjectsWithTag("Respawn");
}
}
[RPC]
void Respawn(){
if(player != null){
Network.Destroy(player);
}
RN = Random.Range(0, spawnPoints.Length);
Network.Instantiate(Resources.Load("Helicopters/Helicopter"), spawnPoints[RN].transform.position, spawnPoints[RN].transform.rotation, 5);
}
void OnGUI(){
if(Network.isClient || Network.isServer){
if(hasSpawned == false && GUI.Button(new Rect(50f, 25f, 150f, 30f), "Spawn")){
Debug.Log("Spawning player...");
networkView.RPC("Respawn", RPCMode.AllBuffered);
hasSpawned = true;
}
if(hasSpawned == true && GUI.Button(new Rect(50f, 25f, 150f, 30f), "Respawn")){
Debug.Log("Respawning player...");
networkView.RPC("Respawn", RPCMode.AllBuffered);
}
}
}
}
Any ideas?
I think neither of these are true, because when there is only a server hosting player, everything works fine
– edve98@Bunny83 wow, now I can't believe I have actually done this, please convert your comment to answer. P.s. I think I will write down the words "Assumption is the MOTHER of all f*** ups" and I will always look at them when something goes wrong :P
– edve98