- Home /
The question is answered, right answer was accepted
Next LEVEL Load Problem.
Ok I have a problem which should be easy to solve.
I have this building that when you enter it, a new level loads with your player in it. The problem comes with placing the player in the new scene in a specific position away from the door so he doesn't go back out when the new scene loads. My player pretty much does not move an inch. Technically still outside even after the new level loads.
So How would I do that?
The code I have isn't working. By not working I mean it has no errors, instead it just does not do what I need it to.
My code for the Entrance/Door:
public string nextLevel;
private Transform plyrObject;
//enterPoint is the point where the player is supposed to be positioned after entering.
public Transform enterPoint;
void Awake(){
GameObject.DontDestroyOnLoad(this.gameObject);
// Posotion player after entering:
plyrObject.position = enterPoint.position;
}
void OnTriggerEnter(Collider col){
if(col.tag == "Player"){
Apllication.LoadLevel(nextLevel);
playerObject = col.transform;
}
}
}
HALP!
http://forum.unity3d.com/threads/200629-Omega-Void-WIP
$$anonymous$$y game. That Hangar type building in the first pic is what this here question is about.
Use OnLevelWasLoaded() to execute code after loading a new scene.
Answer by DeadKenny · Oct 31, 2013 at 04:41 PM
Ok problem solved(yesterday).
I just did all the positioning in the OntriggerEnter as it triggerrrrd.
void OnTriggerEnter(Collider col){
if(col.tag == "Player"){
Apllication.LoadLevel(nextLevel);
col.transform.position = enterPoint.position;
}
}
Wham bam thank you mam.
Answer by Stormizin · Oct 30, 2013 at 04:55 PM
private Trnasform plyrObject;
Transform *
Oh thats a typo. The code has no errors, it just does not do what I want it to.
try to playerObject = new Vector3(x,y,z); Change his position manually
Nope... Perhaps its not referencing the player...
Will make it public and see.
Its not getting the playerObject transform in OnTriggerEnter.
Anyone know why that could be?