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 wlad_s · Dec 05, 2012 at 08:38 PM · sceneprojectaccess

Accessing non-static functions in an unattached, non-scene, "project" script

Hello,

Today I've tried to use LoadLevelAsync for the first time. I have some comic-book images going-on at the screen during the loading process. My idea was to start async download as soon as the comics section starts, and then, when the next level is loaded, I wanted to display a "skip" button that will allow the player to skip the comics and start the loaded level.

I had the GUI function that drives the comics, and the coroutine that loads the level in the same script attached to the object in my scene. I thought that all I need to do is start loading the level and then yield, and then change my static variable levelLoaded to true.

In OnGUI I had it to draw a "skip" button if levelLoaded. But, it doesn't work. I guess it doesn't work because my object with that script is in the scene and it gets destroyed before the levelLoaded variable becomes true. It gets destroyed when the next level is loaded and then it gets recreated. levelLoaded var never becomes true.

So I thought I should make a script with my LoadLevel coroutine and keep it in "project", not to attach it to any object in my scene so it doesn't get destroyed-recreated (restarted). I tried this using "static function" but it can't work since yield can't be used in static functions.

I can think of many ways to go around this problem, but I'm curious now. Is there a way to access non-static functions in "free", unattached scripts that are not in the scene? Javascript please.

Thank you even for reading this :)

Comment
Add comment · Show 1
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 wlad_s · Dec 05, 2012 at 08:48 PM 0
Share

I know that I can make this object not to get destroyed on level load, that's one of the ways to go. But I'm still curious about accessing coroutines in "free" scripts.

1 Reply

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

Answer by Itinerant · Dec 05, 2012 at 09:29 PM

I don't think this is possible, at least not without stepping outside of our normal javascript/C# environment. Anything you use has to be loaded, and once it's loaded it's in the scene. Uber has a really good idea, though, with using a object with a dontdestroyonload command. You can learn the details of how to use it at http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

Only exception I can find to this is by using static variables, which you mention you don't want to use: http://answers.unity3d.com/questions/33229/how-to-pass-boolean-variable-into-another-scene-wi.html

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

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

Same Script in a different Scene with different conditions 1 Answer

Two versions of one game on a single project 1 Answer

My Scene won't load in, and is stuck in "WaitForPlayEnter" 0 Answers

Collision object and access to a script variable? 1 Answer

How can I make night scene? 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