when using prefabs in the game object slots I do not get a null error but it doesn’t keep track of it properly if I let the script find the game object it works but when I switch scenes I get a null reference.`
this script is on a game manager that doesn’t get destroyed between scenes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class doorPanel : MonoBehaviour
{
public GameObject doorPanel_0;
public GameObject doorPanel_1;
public bool unlocked, unlocked1;
public bool locked, locked1;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (doorPanel_0 == null)
{
doorPanel_0 = GameObject.Find("Doorpanel_0");
}
if (doorPanel_1 == null)
{
doorPanel_1 = GameObject.Find("Doorpanel_1");
}
DoorClosed door0 = doorPanel_0.GetComponent<DoorClosed>();
DoorClosed door1 = doorPanel_1.GetComponent<DoorClosed>();
if (door0.doorclosed == true)
{
locked = true ;
unlocked = false;
}
if (door0.doorclosed == false)
{
locked = false;
unlocked = true;
}
}
}