Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nicosim87 · Aug 02, 2012 at 03:25 PM · positionplayerscenelevellocation

Load a Scene and Move the Player to an Specific Location.

Hi to everybody! I have read many answers about this issue, there are a lot of answers about this, with many kind of solutions, however I have been reading them during a week and I still don't understand them, perhaps 'cause I'm starting to learn programing and I really would like someone help me with this:

I'm the player, and actually I'm in a big town with many places to go, but I found a coliseum and I want to enter to it. That big town is actually a scene called "Town" and obviously the internal area of this coliseum is another scene called "Coliseum".

However, this coliseum has 4 doors. All these doors lead me to the internal area, but the position is different because one door is in north, other is in south, other in the east and the other in the west. And when I get back to the town, the corresponding door must lead me to the location where I was in the town. I think this is like when we explore a huge mansion with many doors and rooms...

Many answers say something about to save player last location, but I really didn't understand it. I really prefer to use a script which lead me to the other level and at the same time to move the player to the location I want in that new level, like when we write it using Vector 3.

What script should I use? To which GameObject do I have to apply? To the trigger zone? To the player? Both? To another GameObject? I really would like you can explain me this, please.

Thanks for you help and your time!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Screenhog · Aug 02, 2012 at 04:37 PM

I would probably build a master GameObject that controls game functions, with a script on it that says DontDestroyOnLoad. (This means that the gameObject will continue to exist from scene to scene.) That script would have a variable called "doorID". Then, in the town, each door to go into a building would have its own unique ID number, similar to what strachpr01 said. Every time you hit a door trigger, set "doorID" to the ID of the door you collided with.

When you load the new scene, check which door was most recently collided with, and set the entry position of the new scene based on that.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image strachpr01 · Aug 02, 2012 at 05:28 PM 0
Share

Yes I did start off by thinking of a game manager object. But if I read it right the objects are in separate scenes so unless the positions of the doors are the same in each scene then passing the specific vector across will not work. That's why I changed my $$anonymous$$e and went with the above. If the object are in the same position I would definitely use this one.

avatar image Screenhog · Aug 02, 2012 at 06:13 PM 2
Share

It could still work. Upon entering the "Coliseum" level, you'd have a script that:

  • checks which door was used to get in

  • look for a door in that scene with the same door ID number

  • go to the position of that door

avatar image
0

Answer by strachpr01 · Aug 02, 2012 at 04:06 PM

in the new scene create 4 empty game objects one at each internal door. when the player hits the door collider in the first scene set an int to be 1,2,3 or 4 depending on which door they have hit, you can then reference this in a spawn function for the new scene. you then dont need to worry about getting the vector3 from the first level. in the new scene you just create a 'public Transform[] spawnPoint' variable in a script. drop the four empty game objects into the inspector and in the Start() function set the players position to be the same as the correspoding spawnpoint. so

if(ExampleInt==1){

transform.position = new Vector3(spawnPoint[0].position);

}

just pop this script onto the player and it will move when the level loads

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by reptilebeats · Aug 02, 2012 at 05:39 PM

wild stab in the dark but could you not just put a script on the door that loads the level at a specified position in the next level. and then the script is destroyed on load.

var location : vector3

when door is hit. dont destroy on load

load level,

when level is loaded apply location and then destroy this script

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Nicosim87 · Aug 03, 2012 at 04:55 PM

I already made a test with Michael Gray's solution, but now I have more questions. I couldn't use the var location, because looks like it wasn't read, but I used the DontDestroyOnLoad function, which it managed to take me to the Coliseum, keeping the GameObject with tag("Player") position, however when that happens, the render screen turns gray and I can't see a thing, except in the preview window, and I realized my character survived.

Additionaly, the initial player doesn't destroy when I get back to the Town. Gray is telling me about a function which destroys a script. How can I do that with the initial player?

Look this is what I have in my scripts.

SCRIPT APPLIED TO THE TRIGGER ZONE IN TOWN WHICH LEADS ME TO THE COLISEUM:

 var target : Transform;
 function OnTriggerEnter ()
 {
 DontDestroyOnLoad (target.gameObject);
 Application.LoadLevel ("Coliseum - Internal Zone")
 }
 function Update(){
 }
 

SCRIPT APPLIED TO THE TRIGGER ZONE IN COLISEUM WHICH LEADS ME TO THE TOWN:

 function OnTriggerEnter(other : Collider) {
 if (other.tag == "Player") {
 DontDestroyOnLoad (other.gameObject);
 Application.LoadLevel ("Town");
 }
 }

The strange part is, if I start to play since the Coliseum and I go to Town, the screen is normal, but if I go to Coliseum from Town, the screen turns gray. By the way, the main camera is attached to the player, I already confirmed when the character survives, the camera also does.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nicosim87 · Aug 03, 2012 at 08:24 PM 0
Share

Ignore the gray screen. I already solved that problem, something was hapenning to the player.

avatar image reptilebeats · Aug 03, 2012 at 11:56 PM 0
Share

i use

function OnLevelWasLoaded(){

}

this is a built in function which just says when the application loads a new scene. and then in there i have Destroy(GameObject); to destroy the object i just carried over.

avatar image Nicosim87 · Aug 05, 2012 at 02:08 AM 0
Share

Wow!!! Thanks a lot! I managed to destroy the gameObject using also a public var!

avatar image reptilebeats · Aug 05, 2012 at 02:15 AM 0
Share

i will mention that if you reload the level after the script has been deleted your character may end up somewhere else, so you may want to have a variable set on your character or something that stores the position and then if you reload the current level then use that variable.

but make sure to have it on something like the character which will keep all its properties when a level is loaded. and if you save the game to save it after the position has been stored, or some games will have checkpoints or if its like fallout it can save anywhere, you can save the position when you save it.

avatar image
0

Answer by Rispat-Momit · Sep 15, 2013 at 08:34 AM

Here is a script that I made, it loads a level, changing player's position

 /*
 1. Create a trigger and assign this script
 2. Create a trigger where the player is going to be loaded
 3. Complete the script
 */
 
 var MyLevel:String;
 var MyPlayer:GameObject;
 var Destination : Transform;
 
 function OnTriggerEnter (other : Collider) {
  if (other == MyPlayer.collider) {
  
    Application.LoadLevel (MyLevel);    
 }
 }
 
 function OnLevelWasLoaded(){
  
 
             MyPlayer.transform.position = Destination.position;
         }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Change scenes from area? 1 Answer

How Move Player between Scenes? 7 Answers

How to keep position of a Game Object when switching scene? 3 Answers

Can I utilize LoadLevelAdditive for immersive game? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges