0
\$\begingroup\$

I'm currently working on a 3D Unity game that has 3 levels, but each level has to be unlocked by answering a question to walk through the door leading to the next level. I have a next level trigger collider to move from level to level, but I'm not sure how to create the level trigger for the input field's (correct) element.

Example: What color is the floor? Correct Answer: Blue

Here is the code for the collider/door:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class OnTriggerLoadLevel : MonoBehaviour
    {

public GameObject enterText;
public string levelToLoad;

void Start()
{
    enterText.SetActive(false);
}

// Update is called once per frame
void OnTriggerStay(Collider player)
{
    if (player.gameObject.tag == "Player")
    {
        enterText.SetActive(true);
        if (Input.GetButtonDown("Use"))
        {
            SceneManager.LoadScene(levelToLoad);
        }
    }
}
void OnTriggerExit(Collider player)
{
    if (player.gameObject.tag == "Player")
    {
        enterText.SetActive(false);
    }
}
    }
\$\endgroup\$
2
  • \$\begingroup\$ How much do you already know about the Unity UI system? Would we need to explain it to you from the very beginning how a canvas works? Do you just need to know how to read the value from an InputField component? Or can you already do that and you wonder how to communicate it back to the script you posted here? \$\endgroup\$
    – Philipp
    Dec 31 '21 at 17:10
  • \$\begingroup\$ @Philipp I can make the UI Canvas and I'm working on the inputField component, but I'm mainly lost on how to make the InputField relate to unlocking the door level trigger. \$\endgroup\$
    – Tasneem A.
    Dec 31 '21 at 17:38

You must log in to answer this question.

Browse other questions tagged .