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 goosoodude · Sep 23, 2011 at 11:12 PM · errorbuild

Fps Scriting error.

I have an error with my scripting which will be at the bottom.Script:

 /*
     Usage:
 
     // Load my level    
     LevelLoadFade.FadeAndLoadLevel("mylevel", Color.white, 0.5);
 
     // Reset the current level
     LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 0.5);
 */
 
 static function FadeAndLoadLevel (level, fadeTexture : Texture2D, fadeLength : float)
 {
     if (fadeTexture == null)
         FadeAndLoadLevel(level, Color.white, fadeLength);
 
     var fade = new GameObject ("Fade");
     fade.AddComponent(LevelLoadFade);
     fade.AddComponent(GUITexture);
     fade.transform.position = Vector3 (0.5, 0.5, 1000);
     fade.guiTexture.texture = fadeTexture;
     fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, false);
 }
 
 static function FadeAndLoadLevel (level, color : Color, fadeLength : float)
 {
     var fadeTexture = new Texture2D (1, 1);
     fadeTexture.SetPixel(0, 0, color);
     fadeTexture.Apply();
     
     var fade = new GameObject ("Fade");
     fade.AddComponent(LevelLoadFade);
     fade.AddComponent(GUITexture);
     fade.transform.position = Vector3 (0.5, 0.5, 1000);
     fade.guiTexture.texture = fadeTexture;
 
     DontDestroyOnLoad(fadeTexture);
     fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, true);
 }
 
 function DoFade (level, fadeLength : float, destroyTexture : boolean)
 {
     // Dont destroy the fade game object during level load
     DontDestroyOnLoad(gameObject);
 
     // Fadeout to start with
     guiTexture.color.a = 0;
     
     // Fade texture in
     var time = 0.0;
     while (time < fadeLength)
     {
         time += Time.deltaTime;
         guiTexture.color.a = Mathf.InverseLerp(0.0, fadeLength, time);
         yield;
     }
     guiTexture.color.a = 1;
     yield;
 
     // Complete the fade out (Load a level or reset player position)
     Application.LoadLevel(level);
     
     // Fade texture out
     time = 0.0;
     while (time < fadeLength)
     {
         time += Time.deltaTime;
         guiTexture.color.a = Mathf.InverseLerp(fadeLength, 0.0, time);
         yield;
     }
     guiTexture.color.a = 0;
     yield;
 
     Destroy (gameObject);
 
     // If we created the texture from code we used DontDestroyOnLoad,
     // which means we have to clean it up manually to avoid leaks
     if (destroyTexture)
         Destroy (guiTexture.texture);
 }




 error:

 Assets/Misc Scripts/LevelLoadFade.js(60,30): BCE0004: Ambiguous reference 'LoadLevel': UnityEngine.Application.LoadLevel(String), UnityEngine.Application.LoadLevel(int).
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by msknapp · Sep 23, 2011 at 11:57 PM

You should really switch to using C#. With javascript you do not get as much compilation error help from the IDE. Some problems that would have been detected at compilation if done in C# are instead found at runtime, making it twice as hard to debug. The other problem with javascript is you don't get strong type casting, which is exactly what you have here. The type of the variable "level" is not defined because javascript does not make you define them. At compilation, the unity compiler does not know if your "level" variable will be an int, a string, an object, etc. The function "LoadLevel" is "overloaded". This means there are multiple functions in the Application class with that name, but different arguments. One takes a string as an argument, the other takes an int. Since the compiler does not know what type "level" is, it does not know which method to use when it compiles your application, so it cannot compile.

You need to tell the script what type your variable "level" is. Change this line:

function DoFade (level, fadeLength : float, destroyTexture : boolean)

~to~

function DoFade (level : int, fadeLength : float, destroyTexture : boolean)

~or~

function DoFade (level : String, fadeLength : float, destroyTexture : boolean)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Android Building problem 1 Answer

Distribute terrain in zones 3 Answers

NullReferenceException: Object reference not set to an instance of an object FPSAndroid.Update () 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Building the Scenes 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