- Home /
I can't acces to a class from other class
Hi I'm making modification to the rolller ball standart asset but is can find the other Class where i've saved my variables. In unity 5.
//This is one class
using UnityEngine;
using System.Collections;
public static class StaticVariablesGame
{
public static int PLAYER_LAYER_NUMBER = 8;
public static int PLAYER_LAYER_MASK = (1 << PLAYER_LAYER_NUMBER);
}
// This is on other class. Ball.cs without namespace
Collider[] colliders = Physics.OverlapSphere(transform.position, angleDetection, ~(StaticVariablesGame.PLAYER_LAYER_MASK)); // The name `StaticVariablesGame' does not exist in the current context
Answer by Bunny83 · May 05, 2015 at 09:30 PM
If you don't use namespaces (and it doesn't look like you do) the only possible reason is that your static class is in the normal script-compilation-group and the script that tries to access it is in the first-compilation-group.
Things in the special folders (Standard Assets, Plugins, ...) are compiled before the normal scripts. They can't access anything outside the first compilation group because that is compiled afterwards. The scripts in the normal group (outside those special folders) are compiled after the first group and can access things declared in the first group as well as in the normal group.
So either move your static class into the Standard Assets folder or move the class that uses your static class out of those folders.
See those links for more details:
http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html
But there's a way to change it? and why unity do that?