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 Alanj2007 · Oct 26, 2013 at 02:36 PM · c#

Problem with C#.

This script named "AutoFade"

 using UnityEngine;
 using System.Collections;
  
 public class AutoFade : MonoBehaviour
 {
     private static AutoFade m_Instance = null;
     private Material m_Material = null;
     private string m_LevelName = "";
     private int m_LevelIndex = 0;
     private bool m_Fading = false;
  
     private static AutoFade Instance
     {
         get
         {
             if (m_Instance == null)
         {
         m_Instance = (new GameObject("AutoFade")).AddComponent<AutoFade>();
     }
     return m_Instance;
     }
 }
 public static bool Fading
 {
     get { 
     return Instance.m_Fading; }
 }
  
 private void Awake()
 {
     DontDestroyOnLoad(this);
     m_Instance = this;
     m_Material = new Material("Shader \"Plane/No zTest\" { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Off Fog { Mode Off } BindChannels { Bind \"Color\",color } } } }");
 }
  
 private void DrawQuad(Color aColor,float aAlpha)
 {
     aColor.a = aAlpha;
     m_Material.SetPass(0);
     GL.Color(aColor);
     GL.PushMatrix();
     GL.LoadOrtho();
     GL.Begin(GL.QUADS);
     GL.Vertex3(0, 0, -1);
     GL.Vertex3(0, 1, -1);
     GL.Vertex3(1, 1, -1);
     GL.Vertex3(1, 0, -1);
     GL.End();
     GL.PopMatrix();
 }
  
 private IEnumerator Fade(float aFadeOutTime, float aFadeInTime, Color aColor)
 {
     float t = 0.0f;
     while (t<1.0f)
     {
         yield return new WaitForEndOfFrame();
         t = Mathf.Clamp01(t + Time.deltaTime / aFadeOutTime);
         DrawQuad(aColor,t);
     }
     if (m_LevelName != "")
     Application.LoadLevel(m_LevelName);
     else
     Application.LoadLevel(m_LevelIndex);
     while (t>0.0f)
     {
         yield return new WaitForEndOfFrame();
         t = Mathf.Clamp01(t - Time.deltaTime / aFadeInTime);
         DrawQuad(aColor,t);
     }
     m_Fading = false;
     }
     private void StartFade(float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         m_Fading = true;
         StartCoroutine(Fade(aFadeOutTime, aFadeInTime, aColor));
     }
  
     public static void LoadLevel(string aLevelName,float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         if (Fading) return;
         Instance.m_LevelName = aLevelName;
         Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
     }
     public static void LoadLevel(int aLevelIndex,float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         if (Fading) return;
         Instance.m_LevelName = "";
         Instance.m_LevelIndex = aLevelIndex;
         Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
     }
 }

This script is named "LoadLevel"

 using UnityEngine;
 using System.Collections;
  
 public class LoadLevel : MonoBehaviour
 {
 void OnTriggerEnter(Collider other){
     AutoFade.LoadLevel("Home" ,3,1,Color.black);
     }
 }

"I got an error "The class defined in script file named 'LoadLevel' does not match the file name!"

Comment
Add comment · Show 10
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 meat5000 ♦ · Oct 26, 2013 at 02:57 PM 0
Share

Is using 'LoadLevel' the wisest choice? It's a well known function already in use and yet you define a function LoadLevel, overload that function and define a class by the same name.

Also, check in the file explorer (windows one not unity) for duplicate files.

Duplicates don't normally show in project manager. If you dragged and dropped a file to replace an existing one the old one is renumbered, not overwritten (in my experience).

avatar image Alanj2007 · Oct 26, 2013 at 03:03 PM 0
Share

Am I tripping here or this is just stupid bug?

$$anonymous$$indfuck

loadlevel.png (223.0 kB)
avatar image pako Alanj2007 · Oct 26, 2013 at 03:09 PM 0
Share

I suspect you have 2 LoadLevel.cs scripts at different locations in your Assets folder. One of them has the LoadLevel class and the other the FadeOut class, which gives the error.

avatar image fafase Alanj2007 · Oct 26, 2013 at 03:17 PM 1
Share

There two mistakes you are making here, unrelated to your code. First you post an update as an answer, meaning now your question shows 3 answers. many people will just skip your questions thinking among the three, you probably have your answer.

Second you ask someone in particular, probably because you know that he knows much. Well, then why should I help you if you are waiting on someone else...

avatar image pako Alanj2007 · Oct 26, 2013 at 03:28 PM 0
Share

@fafase +1: Some forum members think that just because someone has more karma that someone else he is more experienced. Well, my program$$anonymous$$g experience is over 3 decades, which is much more program$$anonymous$$g experience than some people with many k's of karma. Yet, @Alanj2007 directs his question to others.

BTW, although I agree that it's not very good practice to name classes the same as well known methods (can be confusing), still it's not an issue here: the well known LoadLevel is a member of the Application class, as in Application.LoadLevel, while @Alanj2007 defines a new class LoadLevel. This would be a problem only of Unity had a LoadLevel class defined.

avatar image Alanj2007 · Oct 26, 2013 at 03:07 PM 0
Share

I will try change something

avatar image meat5000 ♦ · Oct 26, 2013 at 03:12 PM 0
Share

Good stuff. If scene and project is saved, try a reload too :) After loading Unity make sure to reload scene, just to make sure everything is updating in inspector.

avatar image clunk47 · Oct 26, 2013 at 05:46 PM 1
Share

Well I didn't look at it that way, but if it were that way, I totally agree with you. Clunk47 callout deleted, problem solved lol :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Oct 26, 2013 at 04:54 PM

Here is my answer.

If there is anything on your file copy paste on notepad or else. Delete the script, create a new one with same name.

I had this issue before and that solved it.

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

20 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

Related Questions

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

trying to make an object move up and stop via trigger 1 Answer

(sprite2D) Movement like this game... 1 Answer

Csharp: how to make script wait for x seconds 3 Answers

Preserve state of objects when stopping game 0 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