Hi all, I am having a problem with the players position and rotation when entering/exiting a location such as a house. I’m thinking that the code should be after Application
.LoadLevel() but as I’m still learning the C# code and the Unity code I’m unsure how to do it and unfortunately I wasn’t able to find anything.
Here’s part of my code to show what I’m trying to do.
void Update
()
{
GameObject go = GameObject.FindGameObjectWithTag (“Player”);
if (Input.GetKeyUp (KeyCode.X))
{
if (Vector3.Distance (transform.position, go.transform.position) < maxDistance)
{
Application.LoadLevel (2);
interact = false;
}
}
}
Any help on this would certain be appreciated. Also I don’t know if this helps but I do have some game objects in that scene and one of them is a warrior class master at x: -0.14 y: 5 (scale is .7 so it wouldn’t be in the air) and z: 3.12.
Thanks
everyone
wtf is with the links??
no code after Application.LoadLevel will be executed, everything in the scene is dropped and the new scene is loaded fresh. If you need something to persist across the level load you need to include it on a script with DontDestroyOnLoad (Unity - Scripting API: Object.DontDestroyOnLoad) on the gameobject, or within a static class variable
I’m not sure about the links, I might need to run my anti-virus program. Thanks for explaining about the don’t destroy on load but I’m actually trying to figure out that once the new level/scene loads on how to game the position/rotation exactly where it should be. I was watching a few videos and I noticed one way is spawn points through empty game objects but I’m still figuring out the code. Thanks again.
oh, you can just position the player in the new scene in the scene editor. When the scene is loaded it will automatically be where ever you put it (but it will always be in that one place).
Spawn points would be a good approach for if there are several ways a player can move from one scene to another (different doors etc.) and you wanted to place the player as needed. You’ll still need some way of persisting the “which spawn point to use” between scenes as above though.