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 Rxanadu · Jan 08, 2013 at 06:35 PM · c#javascriptfade

Converting LoadLevelFade to C#

I'm trying to convert the LoadLevelFade script from the FPS Tutorial in order to understand how it works. I don't know JavaScript that well, but I do know C#.

I've converted most of the script to C#, but some of the lines are giving me errors or are ultimately confusing to me at the moment. One of them includes a supposed call to another function:

fade.GetComponent("Test").DoFade(level, fadeLength, false);

Unfortunately, the actual function call is bringing up errors. I've tried removing the GetComponent() call from the script and making the function in question static, but it creates other errors in that function as most of the variables used are also not static. However, making some of the variables static will ultimately result in greater headaches in the future.

I'm also having trouble wrapping my head around some of the yield calls included in the original JavaScript. I don't know why they're included in there to begin with.

Both the original and current version of the converted script are included in an attachment in a zip folder for others to look at.

fade-scripts.zip (1.5 kB)
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
Best Answer

Answer by Julien-Lynge · Jan 08, 2013 at 06:40 PM

There are many, many posts on converting between C# and JS. I've posted some links in a blog post for reference (http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/) - since you're a bit more advanced, try the second one. Alternatively, just do a search in the top right widget on this site.

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 Rxanadu · Jan 09, 2013 at 02:19 AM

I'm still having trouble with the yields and coroutines in my script. I've tried following the examples in the documentation, but they only work for creating timers (i.e. with WaitForSeconds() calls).

Here's the area where I'm having the most trouble:

         //fade texture in here
         float time = 0.0f;
         while (time < fadeLength) {
             time += Time.deltaTime;
             textureColor.a = Mathf.InverseLerp(0.0f, fadeLength, time);
             StartCoroutine(DoFade(level, fadeLength, destroyTexture));
         }
         textureColor.a = 1;
         guiTexture.color = textureColor;
         yield return StartCoroutine(DoFade(level, fadeLength, destroyTexture));

Currently, the StartCoroutine() calls are causing the fade GameObject to be created indefinitely, causing an infinite loop and making it unable to stop the game.

If I try to remove the calls or replace them with null return yields, the script breaks and I get an error. If I start the coroutine in my Start enumerator, I get an error saying the coroutine can't start.

Overall, I'm still stumped even after using the links you provided, and I haven't seen any tutorials explaining how to use yields or coroutines in C# properly without using WaitForSeconds() calls (which I'm still not sure if that's the only way to do that process).

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Problem Javascript to C# 3 Answers

dealing with gameObject formations 1 Answer

How to fade out a GUI.Label in GUI.Window? 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