- Home /
Application.LoadLevel ("lower") loads on start-up, not when triggered; Deadline is soon HELP!
When running my game my level should be switched when the player entered a cube. However, my new scene is loaded when game is started. I have this code attached to my cube;
using UnityEngine; using System.Collections;
public class LevelTrigger : MonoBehaviour { void OnTriggerEnter(Collider other) { if (other.tag == "Player") { Application.LoadLevel ("lower"); } }
void update(){
}
void start() {
}
} Can anyone give me any hints as to why it is doing this? I am using the Oculus Rift if this helps. Thankyou!
Is it going straight into that "lower" scene or is it loading the scene you want to be first and then changing scene? (and how do you know?)
If the latter, is it because that OnTriggerEnter() function is being called?
Im not sure I have changed my code to this now and when walking through the cube nothing happens. Im at a bit of a deadend here as im unsure if its even calling it at all! If it helps I am using the Oculus OVRplayer prefab for my user controller
using UnityEngine; using System.Collections;
public class LevelTrigger : $$anonymous$$onoBehaviour { bool cubeupdate = false;
void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
cubeupdate = true;
}
}
void update(){
if (cubeupdate == true) {
Application.LoadLevel ("lower");
}
}
}
Are you calling that update() function yourself somewhere? If you want it to be called automatically by the engine you need to change its name to Update().
And if you want to know if/when the OnTriggerEnter function is being called, just add some logging to it.
Ive updated it and now its loading the first level immediately again. When adding logs it seems that it automatically runs the ontriggerenter method and the update method as soon as it runs the game.
I only can think of your colliders are way too large, maybe 20x bigger than player object, so it still collides when they far away from each other. don't just lift them up. try to pull your cube way out of the map like -1000 Z position, and AFTER stat your game.
Answer by hbalint1 · May 01, 2015 at 04:01 PM
I only can think of your colliders are way too large, maybe 20x bigger than player object, so it still collides when they far away from each other. don't just lift them up. try to pull your cube way out of the map like -1000 Z position, and AFTER stat your game.
Answer by TeohRIK · May 01, 2015 at 03:49 AM
I think you need check your built setting, maybe is your "lower" Scene are set to first running scene, example below. The program will always run the first scene which is 0 that you set in the build settings, to solve that maybe you try to hold and drag your "lower" scene to other number beside of 0
This is the build settings I currently have. Im struggling to find the answer to this because it seems as if it should be working fine
I've already tried this, thank you anyway! Still just loads automatically on start up!
Answer by $$anonymous$$ · May 01, 2015 at 06:56 PM
I think:
void OnTriggerEnter(Collider other) //When the Object with the tag "Player" Enter it's trrigger
{
if (tag == "Player")
{
Application.LoadLevel("lower")
}
}
void OnTriggerStay(Collider other) //When the Object with the tag "Player" Stay in it it's trrigger
{
if (tag == "Player")
{
Application.LoadLevel("lower")
}
}
void OnTriggerExit(Collider other) //When the Object with the tag "Player" Exit it's trrigger
{
if (tag == "Player")
{
Application.LoadLevel("lower")
}
}
Your answer
Follow this Question
Related Questions
how can i load a scene when reaching certain score? Roll-a-Ball Project 1 Answer
Distribute terrain in zones 3 Answers
Make object react to certain triggers only 1 Answer
Where is this (-1) coming from in my change level script? 1 Answer
OnTriggerEnter() and OnTriggerExit() called multiple times despite checks. 3 Answers