I have a referenced gameobject (starts disabled) in a C# script, but when I try to use it, the object reference in the editor goes from the object, to saying Missing.
There is nothing in the script that sets the removal, not anything called which would do this, so I am at a loss to explain it.
The script is a unique, use-once script to control the initial cutscene, so is quite specific.
The variable that is disabled, and disappears is “player”, and occurs when I try to enable it, on line 32.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameStartControl : MonoBehaviour
{
public GameObject playerCryo;
public GameObject player;
public int secondsToStart;
void Start()
{
StartCoroutine(StartGO());
}
IEnumerator StartGO()
{
FadeInOut[] fade = Resources.FindObjectsOfTypeAll(typeof(FadeInOut)) as FadeInOut[];
yield return StartCoroutine(WaitFor.Seconds(secondsToStart));
foreach (FadeInOut f in fade)
{
f.FadeOut(); Debug.Log(f.name);
}
yield return StartCoroutine(WaitFor.Seconds(3));
playerCryo.SetActive(false);
player.SetActive(true);
foreach (FadeInOut f in fade)
{
f.FadeIn();
}
}
}