I am having this error that i can’t seem to fix
NullReferenceException: Object reference not set to an instance of an object
NetworkManager.SpawnMyPlayer () (at Assets/NetworkManager.cs:37)
I have been looking and trying but nothing (I’m new to Unity)
I am trying to spawn my player in the world by setting spawnpoints but it won’t spawn the player in
When i do debugging it says that SpawnSpot [ ] spawnSpots; = Field ‘NetworkManager.spawnSpots’ is never assigned to,and will always have it’s default value null. So i need to know how to fix this.
Here is my NetworkManager
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
SpawnSpot [ ] spawnSpots;
// Use this for initialization
void Start () {
SpawnSpot [ ] spawnSpots = GameObject.FindObjectsOfType ();
Connect ();
}
void Connect () {
PhotonNetwork.ConnectUsingSettings (“Unamed Game V001”);
}
[Mistake] Also, Random.Range min and max values are both inclusive, which means you need to pass spawnSpots.Length - 1 as the max value or you could get an out of bounds exception (or whatever C# exception throws for this type of error).
EDIT: And for safeness’ sake you might want to check that spawnSpots.Length is > 0.
EDIT2: Sorry about that, indeed its exclusive for int. Quite odd…
Carpe Denius the player spawns now thank you very much for that. But now my player is falling through the ground.
(EDIT) I bumped the spawnpoints up so I don’t fall through the world. BTW I used cubes to make the spawnpoints if i wanted to make them invisible would i need to delete the Mesh Renderer?
Alright so I fixed the spawns now I have 1 more problem is that my player isn’t able to jump. I know how to setup keys but when i type in like ‘Spacebar’ it auto gets removed. So what keybind does jump have on Unity?