I've run into some accessibility problem with one of my Unity projects. I created a class that does NOT inherit from MonoBehaviour
. It has a method public static void LoadScene(string sceneName)
.
When I try to call this method from another class, I get a syntax error. This is my first script with the static method:
public class GameLoader
{
public static void LoadScene(string sceneName)
{
SceneManager.LoadSceneAsync(sceneName);
}
}
And here is my other script:
public class GameHandler : MonoBehaviour
{
private void Start()
{
GameLoader.LoadScene("MyScene"); //Syntax error
}
}
Normally, I would have some idea about what might the problem be, but in this case, the GameHandler
recognizes GameLoader
as class, but after the dot (GameLoader.
), it does not find any property or function at all. And I get a syntax error when I try to write anything after the dot.
I experimented a little and it doesn't seem like I would cross another class with the name GameLoader
and the neccessary namespace was added as well.
I'm pretty lost here, I hope someone can help me out.
Original codeGameLoader
:
using UnityEngine.SceneManagement;
using UnityEngine;
namespace MyGame
{
namespace System
{
public class GameLoader
{
public static void LoadScene()
{
}
}
}
}
Original UIHandler
:
using UnityEngine;
using System;
namespace MyGame
{
namespace System
{
namespace UI
{
public class UIHandlerMenu : MonoBehaviour
{
GameLoader.LoadScene();
}
}
}
}
Error message:
Severity Code Description Project File Line Suppression State Error IDE1007 The name 'GameLoader.LoadScene' does not exist in the current context.
And the same error for just LoadScene
itself.
GameLoader
script in the assets once, do you see its content in the Inspector? Are there any other compiler errors? And do you get the error in Unity or maybe only in your IDE?GameLoader
in a referenced dll/project?