Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by huarn · Oct 26, 2015 at 04:54 PM · unity 52drpg

How to differ between LoadLevel and starting the scene for the first time

I want my players position to depend on wether the scene is just starting for the first time or if it was called from a different scene, I can't seem to manage doing this. What I'm looking for is maybe a condition or script that checks if the whole game (which starts in "Scene1") is just starting for the first time or if its being called with Application.LoadLevel later in the game.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fffMalzbier · Oct 26, 2015 at 04:58 PM

You can create a manager script that will survive the loading / cleanup of a level. In that script you can store all the informations you will need to determine what scene was the last one. You can call DontDestroyOnLoad(gameObject); from your manager script and it will loading / cleanup of a level. http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

You should make sure to only have one instance of the manager script loaded( in case you load the scene that contains the manager object again).

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 Statement · Oct 26, 2015 at 05:24 PM

If you don't want to remember if you've been to a particular level before between game plays, you could keep a static bool array large enough to hold all your levels.

 const int MaxLevels = 50;
 static bool[] hasVisited = new bool[MaxLevels];
 
 void OnLevelWasLoaded(int level) 
 {
     bool visited = hasVisited[level];
     hasVisited[level] = true;

     if (visited)
     { 
          // Do something
     }
 }

If you want to remember you've been to a particular level between game plays, use PlayerPrefs or write your own savegame file handling.

 void OnLevelWasLoaded(int level) 
 {
     string lvlname = Application.loadedLevelName;
     bool visited = PlayerPrefs.GetInt("hasVisitedLevel_" + lvlname, 0) != 0;
     PlayerPrefs.SetInt("hasVisitedLevel_" + lvlname, 1);

     if (visited)
     { 
          // Do something
     }
 }

Note that it can get annoying to develop with PlayerPrefs setting the level as been visited so you may want to switch to either mode depending if you're in the editor or not.

Comment
Add comment · Show 1 · 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 Statement · Oct 26, 2015 at 05:28 PM 0
Share

You may want to use Application.loadedLevelName ins$$anonymous$$d of an integer in playerprefs. If you keep rearranging the order of the levels, the integer level will no longer be correct.

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

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

Related Questions

i have created a wheel and added the rotation now its rotating in the anticlockwise direction,how can it made to be rotated in the clockwise direction 0 Answers

Unity jump from one canvas scene to another scene with canvas 2 Answers

Disable load new level until all enemies are dead 2 Answers

How to randomize a stages with no repetition? 1 Answer

Having a couple of problems regarding 2D Movement. 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