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 eXtremeTY · Feb 25, 2014 at 10:10 PM · spawnloadinglevelloadlevel

Move my entire player gameobject in the next scene (using loadlevel)

Hey all,

I'm working on a platformer and I have one scene which is supposed to be like open world and a small building with a door that's supposed to be a shop building. I'd like when player gets to the door and press UP to be able to spawn in the new scene called house.unity. I tried several ways and read around dozen of websites/answers to the similar issue but couldn't find a complete answer :/

There are two main issues: a) I want to keep the player, for example even tho player starts first as a prefab, once the user is playing the game, player is supposed to gather weapons and those show up on the character as well.. Simply instantiating a basic player prefab in a store is a big no-no.. + I want to keep player's score, money, attributes etc..

b) I want to keep track of x/y coordinates of door entrance, so when I later want to exit the shop I'll be spawned just outside it..

Now I read A LOT about PlayerPrefs, DontDestroyOnLoad, OnLevelWasLoaded or even using a static variables but still find it hard to find the best or working way :/

So the scenario is: -Player is spawned into a world at a start of a new game by simply instantiating player prefab at designated spot.

-Camera isn't father/child of player, it's another GameObject floating in hierarchy that follows player via code.

I have a world and a door. Door has a trigger and is supposed to enable loading of level "house_01.unity".

The "house_01.unity" contains scene with merchant and a door. Does this scene needs another camera? a spawn point?

How can I TAKE my player, totally cut and paste it at "house_01.unity" at lets say empty gameobject with name "spawnMeHere" and also move a camera into that scene as well?

It might looks like I'm lazy and I want YOU to do the work instead of me, but I spent a good 3-4hrs just looking for solution and I'm not getting it :(

Thanks all

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Olgo · Feb 25, 2014 at 10:21 PM

You can transfer data between scenes by writing data to a static variable. You could have one class that stores all your transferable information.

 public static class GameSettings{
 
  public static Character save;
 
 }

You can write to this by having a line whenever you change scenes like "GameSettings.save = characterStats"

or something like that. use as many variables as you need or save the whole class. However, this wont save when you shut down your game. You need to use player preferences for something like that.

Also, to spawn your character at a certain location, have a script that moves the character when the scene loads. You can have an empty gameobject on the location you want him to appear. The script could say something like "player.transform.location = GameObject.FindObjectWithTag("spawnLocation").transform.location;" Where spawnLocation is the tag on your empty gameobject denoting your spawn point.

Additional info, each of your scenes does need its own camera and spawn point unless you have it attached to the player prefab as part of the prefab

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 eXtremeTY · Feb 25, 2014 at 10:27 PM 0
Share

So, what you're saying is that ins$$anonymous$$d of me looking for a way to in a sense "cut and paste" my player every time I go to the new scene, I should keep a list of information, and each time I load a new scene spawn a new, generic prefab of my player and on the run-time assign different info that corresponds to player's progress in the game?

The trouble I'm having with moving my player around a newly loaded screen is because after line:

...Application.LoadLevel(X);

Any code after that isn't executed, so I'm a bit confused as to where that code, in your case "player.transform.position =...." should be?

Thanks for helping!

avatar image Olgo · Feb 25, 2014 at 10:39 PM 0
Share

not a problem.

What I would do is have an empty GameObject that appears in every scene that has a script that does the following in the "Start()" function.

Instantiate playerPrefab, find spawnPoint gameObject for current scene, set playerPrefab's location to spawnPoint's location, set player's stats to the last saved stat (for example, gold = saved gold; health = savedHealth; score = savedScore;), whatever else you need

avatar image eXtremeTY · Feb 26, 2014 at 01:28 AM 0
Share

2h later and I solved it! :) Thank you for pointing me in the right direction!

avatar image Olgo · Feb 26, 2014 at 01:38 AM 0
Share

no problem, glad to help

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

scene loader issue 0 Answers

Reloading Level problem 0 Answers

getting loading progress for a level 1 Answer

Animated Loading Screen Unity Indie 0 Answers

Load music only when everything is loaded 1 Answer


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