- Home /
Public string/GameObject not in inspector
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OnTriggerLoadLevel : MonoBehaviour { public GameObject guiObject; public string levelToLoad;
private void Start()
{
guiObject.SetActive(false);
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "soda")
{
guiObject.SetActive(true);
if (guiObject.activeInHeirarchy == true && Input.GetButtonDown("Use"))
{
Application.LoadLevel(levelToLoad);
}
}
}
private void OnTriggerExit()
{
guiObject.SetActive(false);
}
}
Did your script compile successfully without any error? And what Unity version are you using? I remember there was a bug in the previous Unity 5 and Unity 2017 (I forgot which patch) where the editor show compiling completed but it didn't use the new edited codes ins$$anonymous$$d it keep using the old codes (codes before you edited) unless you intentionally make an error (delete ;
or something) then make it compile error and then correct the error and let it compile again to fix that bug (And you have to do that over and over again every time you edit the script)