So I have a NullReferenceException I can't see the problem with. I'n the Debug Log I get:
/Game Projects/LaZeR/Assets/Scripts/PlayerSpawner.cs Line: 37)
NullReferenceException: Object reference not set to an instance of an object
at PlayerSpawner.Die () [0x00001] in C:\--\--\Game Projects\LaZeR\Assets\Scripts\PlayerSpawner.cs:37
but the code on line 37 looks fine to me:
PhotonNetwork.Instantiate(deathEffect.name, player.transform.position, Quaternion.identity);
Can anyone steer me in the right direction? I'm still quite green so I'm just missing little things, I appreciate everyone's patience with me :)
Here is the full code, 42 lines in total:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerSpawner : MonoBehaviour
{
public static PlayerSpawner instance;
private void Awake()
{
instance = this;
}
public GameObject playerPrefab;
private GameObject player;
public GameObject deathEffect;
// Start is called before the first frame update
void Start()
{
if(PhotonNetwork.IsConnected)
{
SpawnPlayer();
}
}
public void SpawnPlayer()
{
Transform spawnPoint = SpawnManager.instance.GetSpawnPoint();
player = PhotonNetwork.Instantiate(playerPrefab.name, spawnPoint.position, spawnPoint.rotation);
}
public void Die()
{
PhotonNetwork.Instantiate(deathEffect.name, player.transform.position, Quaternion.identity);
PhotonNetwork.Destroy(player);
SpawnPlayer();
}
}