Scene-loading code
Hi everyone, I come again, for a question.
Firstly, here's the scene:
I searched the Internet how to do, and unfortunately I have not found any solution for my request. I want when the player approaches an object (example here: the television), an information message and prompt to press a key (E or F). Once the player presses the button, a scene starts.
Thank you very much for reading, and thank in advance those who will help me.
Have a good day.
Answer by Jessespike · Mar 18, 2016 at 03:59 PM
Use Physics.Raycast
Here's an example:
float distance = 3f;
RaycastHit hitInfo;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, distance))
{
if (hitInfo.transform.name == "TV")
{
Debug.Log("Display your message");
if (Input.GetKey(KeyCode.E))
{
SceneManager.LoadScene(1);
}
}
}
Thank you for your answer. Regarding the code, I have to put in #C or Java?
Your answer
Follow this Question
Related Questions
HUD Header need to be rendered for all scenes 0 Answers
the level does not charge 0 Answers
Fade out / fade in scene w/ loading screen 0 Answers
Rhino model cannot be seen 0 Answers
Unity Scene Navigation on X and Z plane 0 Answers