having an issue with loading a level have a key that when picked up sets doorKey4 = true but when i have it in this script will not work but when removed it loads level fine. when used with door script works fine if i havn’t picked up key door doesn’t open pick up key door then opens
using UnityEngine;
using System.Collections;
public class loadasylum6 : MonoBehaviour
{
public static bool dooKey8;
public bool inTrigger;
void OnTriggerEnter(Collider other)
{
if (dooKey8)
{
inTrigger = true;
}
}
void OnTriggerExit(Collider other)
{
inTrigger = false;
}
void Update()
{
if (inTrigger)
{
Application.LoadLevel("Asylum6");
}
}
}
Please use code tags. Otherwise it’s hard to tell sometimes what is going on, especially if spacing doesn’t line up.
I am curious why you need to check in update if they have the key and if they are in the trigger. If they enter the trigger without the key, they wouldn’t proceed to the next level, right? If this is the case, you could simply check if they had the key when entering the trigger instead of checking in update repeatedly.
Also depending on your setup, if they can’t even reach the trigger without the key, you could probably just assume they have it when they hit the trigger and not even need the check.
I would say, make sure that doorKey4 is being set to true and not being changed back to false somewhere after it is being set to true.
ok made changes edited above still same not loading level if " if (doorKey8) " is in code also trigger is able to be entered at anytime but only want to activate if doorKey8 is picked up. Here is code for doorKey8 pretty straight forward
using UnityEngine;
using System.Collections;
public class DoorKey8 : MonoBehaviour
{
public bool inTrigger;
void OnTriggerEnter(Collider other)
{
inTrigger = true;
}
void OnTriggerExit(Collider other)
{
inTrigger = false;
}
void Update()
{
if (inTrigger)
{
if (Input.GetButtonDown("Fire1"))
{
DoorScript8.doorKey8 = true;
Destroy(this.gameObject);
}
}
}
void OnGUI()
{
if (inTrigger)
{
GUI.Box(new Rect(0, 60, 200, 25), "Press E to take key");
}
}
}