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 Knightraven8 · Sep 18, 2012 at 07:26 AM · scenesswitchplayersbetween

Application.LoadLevel loading the current scene instead of the specifed one

I am working on a game where players take turns firing cannonballs at each others castle. After Player 1 fires, I want the game to wait a few seconds, then load player 2's scene, and vice versa.

I used Application.LoadLevel to try to do this, but instead of loading the level I try to pass in, it reloads the current scene. My scenes are called Player1 and Player2, and both are loaded into the build settings. I have tried calling Application.LoadLevel with both the build ID for the scenes and their names, but neither seems to actually cause the correct level to load.

Here is my code:

var activePlayer : String = EditorApplication.currentScene; Debug.Log(activePlayer); if (activePlayer == "Assets/Scenes/Player1.unity"){ yield WaitForSeconds (6); Application.LoadLevel("Player2"); print("Player 2's Turn"); } else { yield WaitForSeconds (6); Application.LoadLevel("Player1"); print("Player 1's Turn"); } }

Regardless of which scene I run the script from, it will print the scene name correctly when I assign it to the string activePlayer, and the if check correctly causes the game to print player 1/player 2's turn depending on which scene is active.

The issue is that I can't seem to get Application.LoadLevel to switch the scenes, as it currently just reloads whichever one is currently active.

Comment
Add comment · Show 3
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 whydoidoit · Sep 18, 2012 at 08:08 AM 1
Share

You aren't using EditorApplication.currentScene in the game are you? That isn't going to work when it's built - you need to be using loadedLevelName

avatar image Knightraven8 · Sep 18, 2012 at 08:58 AM 0
Share

That's exactly what I was doing. Thanks!!!

avatar image Knightraven8 · Sep 18, 2012 at 09:02 AM 0
Share

I just tried out loadedLevelName and it worked perfectly.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jaskij · Sep 18, 2012 at 07:36 AM

If they're indeed shooting at each other, changing the scene for that seems kinda strange... Shouldn't you rather just switch the camera?

And you have to set up the levels in the build options for them to load through Application.LoadLevel();

Comment
Add comment · Show 5 · 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 Knightraven8 · Sep 18, 2012 at 07:52 AM 0
Share

They are both shooting, but the way I can really only have 1 castle on screen at once because the bricks in the castle are all rigidbodies that interact with whatever hits them, and 2 castles causes too much lag. I want to set it up so that player 1 takes a shot, then it saves his scene and switches to player 2, who then takes his shot (sort of like battleship). I made sure that both scenes show up in the build options, I'm just not sure why Application.LoadLevel is not actually loading the level I pass in and is just reloading the current scene.

avatar image jaskij · Sep 18, 2012 at 07:59 AM 0
Share

A ton of rigidbodies, and on a V$$anonymous$$ no less... Or are you compiling it to an exe? No easy way out here though, methinks.

avatar image whydoidoit · Sep 18, 2012 at 08:11 AM 1
Share

Saving the positions and forces on all of those rigidbodies between level switches is going to take forever and you are going to have to use a plugin or write the code for it yourself - Unity does not have that feature built in.

I would suggest that you:

  • Have both castles in the same scene

  • Don't attach rigidbodies to start with - only add them when you can identify that they are going to be hit - or sleep them all manually to reduce the lag issues.

  • Use fewer bricks

avatar image Knightraven8 · Sep 18, 2012 at 08:59 AM 0
Share

Thanks for the advice on reducing lag.

avatar image Fattie · Sep 18, 2012 at 09:15 AM 0
Share

For the record. If you're trying to make an "angry birds" -like scene.

That does not actually use PhysX. It uses a 2D physics library, such as Cocos2D or chipmunk.

remarkably I believe someone has ported Cocos2D here to Unity .. just search on the forums. Hope it helps in some way.

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

13 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

Related Questions

time between scenes (loading time) 0 Answers

switch player and npc follow player 0 Answers

How to switch between cameras/players? 1 Answer

Transfer data between scenes + saving it C# 1 Answer

Passing "best" to the other scene 0 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