- Home /
Door to Next Level HELP!
Hi! For about 2 days I have been trying without success to create a door that brings you to a different scene like from a Fallout game or Elder Scrolls game. I've been trying to make it so that when you are within a distance and your cursor is pointing towards the door, then it will say 'Click F to Enter "Scene"' And then when you click F it brings you to a Different scene. Like in my game you spawn in your home and you want to go outside, I was manageable to make it so if you click a key like 'F' then it takes you "Outside" but I could do that anywhere like from halfway across the room not even looking at the door... If you can help me it would help alot!
Answer by Flickayy · Jan 26, 2013 at 05:41 PM
Take a look at Application.LoadLevel for loading different scenes.
// Load the level named "HighScore".
Application.LoadLevel ("HighScore");
You could then use Triggers and the method OnTriggerEnter to check if the character is near the door, then load the level when "F" is pressed. Something a long the lines of this. I know it's not exactly the method you wanted, but I hope you can at least use some of this.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnTriggerEnter(Collider other) {
if(other.gameObject.name == "DoorTrigger"){
if(Input.GetKey("F")) {
Application.LoadLevel("NextScene");
}
}
}
}
Answer by Kortekk · Jan 26, 2013 at 05:37 PM
Look into use raycasting in order to detect whether the player is facing an interactive object:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
You can adjust the distance parameter to change the minimum interaction distance.