- Home /
How do I load a scene by walking into a trigger box and pressing E or Enter?
So I'm following this tutorial: https://www.youtube.com/watch?v=tCe_UfyirT4 and the part where I'm getting stuck is that the text doesn't appear and pressing either E or Enter doesn't work.
I was watching in his video that in input settings he has an extra option called "use" (which is where I'm sure the problem might be coming from but I'm not sure) but I also have a pause screen canvas that might also be causing some interference(which again is just a guess as I'm not a pro)
I can't upload or share any part of the game due to copyright reasons but I can take screenshots of settings and such if that helps :)
Answer by AR_Rizvi · May 24, 2017 at 05:13 AM
Hi Try this
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LoadSceneOnEnter : MonoBehaviour
{
public string SceneName;
void OnTriggerEnter(Collider other)
{
if (other.tag == "AnythingYouLike")
{
SceneManager.LoadScene(SceneName); // loads scene When player enter the trigger collider
}
}
void OnTriggerStay(Collider other)
{
if (other.tag == "AnythingYouLike")
{
if (Input.GetKeyDown(KeyCode.E)) // loads scene on user input when in collider
{
SceneManager.LoadScene(SceneName);
}
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E)) // loads scene on user input From anywhere
{
SceneManager.LoadScene(SceneName);
}
}
}
and as for your input
Thank you so much, I was stuck on this for ages! :D
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
put a void in an if statement? 1 Answer