- Home /
Same level loading even I give different level name to objects.
Hi everyone, okay so I have a scene with a chair and a bookshelf. I have added box-collider with "is trigger" checked. Now when our character collides with these object different levels should load. So I added this script to both object:-
var textHints : GUIText; var levelToLoad : String;
function OnTriggerEnter(col : Collider){ if(col.gameObject.tag == "Player"){ textHints.text = "Press E to interact"; } }
function OnTriggerExit(col : Collider) { if(col.gameObject.tag == "Player"){ textHints.text = ""; } }
function Update(){ if(Input.GetKeyDown(KeyCode.E)){ Application.LoadLevel(levelToLoad); } }
I have already saved 2 level namely Book and Chair and added them to Build setting also.
Now even I added different scene to both our objects, only Book level is loading...
Thanks in advance...
Tru to use an int ins$$anonymous$$d of a string to load the level: In the build settings you see that every level has his own ID (level0 - 0, level1 - 1 etc..). So lets say the level you want to load is the second in your build settings: var levelToLoad : int = 1; // Index starts from 0
Why are you attaching this script to both objects? Then you risk running the same code twice.
Your answer
Follow this Question
Related Questions
Ignore collision at high velocity. 1 Answer
Trouble with Physics.IgnoreCollision 0 Answers
Unwanted jittery behavior 2 Answers
Colliders in a wall jut out 0 Answers