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 Panik.Studios · Aug 19, 2012 at 10:08 AM · spawningdontdestroyonload

Don't Destroy on Load Function is not working for me, and...

First off, I have only been using Unity for a couple of days... and I am completely new to scripting (not saying Im not willing to try to write something myself, only saying If you go all "yoda on me I may not have a clue what you're saying cause I'm still a fish")

// I have this .js

function Awake(){

DontDestroyOnLoad (transform.gameobject);

}

attached to my Player my player has tag : Player

//I have this .js

function OnLevelWasLoaded(level : int) { if (level == 1){ GameObject.FindGameObjectsWithTag("Player"); transform.postiton = Vector3(-30,1.5,0); transform.rotation = Quaternion(0,90,0,0); }

}

//My huge issue....

When the new scene is loaded.. My Player from the previous scene doesn't spawn or whatever u want to call it.. basically leaving me with just a camera that I had already positioned in the new scene, with a smooth follow script targeting my Player who somehow got lost in the time-space continuum/blackhole of unity engine.. and of corse my beautiful un-explorable terrain.. I'm so very confused and tired. The new scene is (1) in the Build settings..

Also, I do not wish to have a carbon copy of player in my starting scene.. as I am making an mmorpg style game at the moment and dont want thousands of players (assuming my game is epic when finished) standing at the trigger... So if my methodology here will do that can you please steer me in a good direction..

Also*2 Is there a way to look up last level loaded in memory like example : lastloadedlevel == 0?

Oh, and at what point am I trusted enough to not have all my posts reviewed by an Admin if ever.. I'm an Impatient Person? Thanks so much peoples hopefully Yall can help me.

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
1
Best Answer

Answer by Panik.Studios · Aug 21, 2012 at 08:18 AM

Answer

This is to Be Placed on the "Player"

 function Awake(){
 
 DontDestroyOnLoad (this);
 
 }

And this Code ...

 function OnLevelWasLoaded(level : int)
 {
     if (level == 1){
         transform.position = Vector3(-30,1.5,0);
         transform.rotation = Quaternion (0,90,0,0);
     }
 }

This Script is to be placed on the event trigger (box collider anything ect)

 function OnTriggerEnter (other:Collider)
 {
     if(other.CompareTag("Player"))
     {
         Application.LoadLevel("Cave of Discovery");
     }
 }
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 Panik.Studios · Aug 19, 2012 at 10:32 AM

Ok I added debug.log("script works") to the code and it didnt log it so something is going foofy in the LoadLevelscript for sure?

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 Khada · Aug 19, 2012 at 11:03 AM 0
Share

So this line:

"DontDestroyOnLoad (transform.gameobject);"

isn't being called?

avatar image Panik.Studios · Aug 19, 2012 at 06:34 PM 0
Share

No I don't believe so. Otherwise it would say "Script Works" in the editor right?

avatar image Khada · Aug 20, 2012 at 07:09 AM 0
Share

I don't know, I can't see your code. What matters it that it's not being called, thus it can't take effect. You need to debug your code, and see why it's not reaching that line etc.

avatar image Panik.Studios · Aug 21, 2012 at 06:15 AM 0
Share

I got everything working now.. do you know how I can close this question?

avatar image AlucardJay · Aug 21, 2012 at 06:21 AM 0
Share

You don't need to close the question, just mark the answer that you accept. Here is my generic post for new users =]

I wish this was made clearer for new users, so just some tips on using this 'site (for ALL new users) :

How to accept an answer :

On the left-hand-side of the Answer box , there are the following icons :

: Thumb Up : Number (of votes) : Thumb Down : A Tick :

If an answer worked for you , click on the 'Tick' , the answer should now be highlighted in green. If you like an answer on Any question , you can click on the Thumb UP , the thumb should now be highlighted in green , and the number of votes should rise by 1.

How to reply to an answer / post a comment :

To make a comment , USE the [add new comment] button, a window then opens to type in. The answer fields are for ANSWERS, so unless you are answering your own question , DON'T write in an answer box. This helps the 'site work properly, especially when other people are searching for answers, and want to read answers , not comments.

IF your question changes slightly while commenting and reading comments , EDIT the original Question, so anyone reading from the beginning knows what you are asking.

This will make for a happy experience for everyone. I made mistakes starting on this 'site too, but everyone is helpful if you learn and change these habits.

Following these simple steps helps the website work , and other readers to find answers also.

Happy Coding =]

the FAQ appears at the top of the page : http://answers.unity3d.com/page/faq.html

also : http://answers.unity3d.com/questions/133869/how-to-ask-a-good-question.html

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

10 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

Related Questions

DontDestroyOnLoad() does not seem to be working. 3 Answers

random respawn and respawn delay 1 Answer

How to make a spawner? 1 Answer

How to respawn items along with player 1 Answer

Spawn and Destroy problem snake like 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