- Home /
Unity 5 OnTriggerEnter Change scene, Not working
Essentially im attempting to create a gameobject, make it a trigger, and have the first person controller, the new one from unity 5 by the way, go into and change from the current scene to a different one.
When i try to add this script to my empty gameobject, it tells me it is an editors script and cannot be added to the empty game object, i want to know how to either fix this, or get around this.
personally, this is especially frustrating because its only since unity 5 has this been a problem for me, in fact, with scripting having a complete overhaul, the code is unnecessarily longer.
Can we see the Change Scene script? I assume you have some sort of...
protected void OnTriggerEnter() {
if collision....
}
setup going on?
Or JS?
function OnTriggerEnter( col : collider ){
if ( col.CompareTag("SceneSwitcher"){
//loadlvl
}
}
A gameobject cannot be a trigger. A gameobject can have a collider component attached to it that is set to be a trigger, which I suspect is what you meant, but it won't do anything unless you also attach a script component that implements one of the OnTriggerXXX functions.
If you have a problem with such a script, you need to post that script with your question, along with the full, accurate error message it generates.
There have been some changes to the scripting API between 4.x -> 5.x, but certainly not a complete overhaul. The biggest single change is the removal of .transform, .collider etc. shortcuts to GetComponent. That's it.
I have a gameobject that has a box collider, set to "Is Trigger" I have a loadlevel attachment to the ontriggerenter. when i attempt to apply the loadlevel script, it says it is an editors script, and cannot be added.
Answer by anthodb · Jun 18, 2015 at 04:13 PM
I had same issue and I had to set both of my colliding Gameobjects on the "CollisionLayer". Then it worked ;) I don't know if this is a new feature of Unity5 but I can tell I spent most of the day searching for a solution.. Hope that helps..
Your answer
Follow this Question
Related Questions
Player object carried from scene to scene 1 Answer
Change scenes from area? 1 Answer
carrying player data from one scene to the next 1 Answer
Load scene when colliding on GameObject 1 Answer
When Near Object, Change Scene 0 Answers