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 /
avatar image
0
Question by Porcus · Aug 21, 2017 at 11:32 AM · unity 5loadlevelapplication.loadlevel

Load Scene Script doesn't work anymore

Hello everybody,

my script, which worked a few weeks ago in another Project, doesn't work anymore and I don't know why.

My Problem: I want my Player Object to load a scene when the Player collides with a collider2D. In addition I want my Player Object in the other scene (which should be loaded) to load on a certain point (which can be added in the inspector). Although the scene loads, the Player Object doesn't load there where I want it to load.

My code is below as a comment. If anyone knows what is wrong please tell me. There are no error messages, except that Application.LoadLevel is obsolete. But I don't want to change that.

Thanks in advance.

P.S.: There are a LOAD of loads in this question. :)

Comment
Add comment · Show 2
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 Porcus · Aug 21, 2017 at 11:33 AM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Script Name : $$anonymous$$onoBehaviour {
 
     public string sceneName;
     public float xPosition;
     public float yPosition;
 
     void OnCollisionEnter2D(Collision2D col) {
         if (col.transform.tag == "Player") {
             col.transform.position = new Vector3 (xPosition, yPosition);
             Application.LoadLevel (sceneName);
         }
 
         
 
     }
 }
avatar image christoph_r · Aug 21, 2017 at 12:38 PM 0
Share

So, the scene is loaded but the player is not placed at the specified location?

1 Reply

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

Answer by efeguclu · Aug 21, 2017 at 11:46 AM

use DontDestroyOnLoad() method in awake;

 void Awake(){
       DontDestroyOnLoad(gameObject);
 }
Comment
Add comment · Show 3 · 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 Porcus · Aug 21, 2017 at 12:35 PM 0
Share

Thanks for your help. I tried this method days ago but it didn't work. When I attach it to the "Collision-Wall-Load-Scene-Object", it appears in the other scene at the same point. If I attach it to my Player, my Player Object got stuck in a spawning loop. That's funny, but not helpful.

If you have any other suggestions I would be very grateful.

Thanks.

avatar image tanoshimi Porcus · Aug 21, 2017 at 01:11 PM 1
Share

It needs to be attached to your player - the thing that you want to retain its position between scenes. And you also need to make sure that that object doesn't exist in the scene hierarchy of the new level you're loading.

avatar image Porcus tanoshimi · Aug 21, 2017 at 01:30 PM 0
Share

Thank you very, very much. That makes sense. If there are two player objects both get loaded and so I can avoid the infinite spawn loope. Thanks!

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

139 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 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 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

Application.LoadLevel(Application.LoadedLevel) causes freeze 0 Answers

Script looses attached AudioSource when level is restarted 1 Answer

Application.LoadLevel() changes lighting for some reason? 12 Answers

How to choose coordinates on Application.loadlevel 2 Answers

How to load Level using scene object?? 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