To access it from another script you need to use the name of the script followed by a dot and the global variable name.print(TheScriptName.someGlobal);
TheScriptName.someGlobal = 10;
То есть Имя_класса.Поле.
На MSDN тоже так написано:
Синтаксис:
Используется csharp
public class Employee4
{
...
public static int employeeCounter;
}
class MainClass : Employee4
{
static void Main()
{
...
Employee4.employeeCounter;
}
}
{
...
public static int employeeCounter;
}
class MainClass : Employee4
{
static void Main()
{
...
Employee4.employeeCounter;
}
}
Решил создать класс, производный от MonoBehaviour и в нем - статическую переменную:
Синтаксис:
Используется csharp
public class Ladder : MonoBehaviour {
// Статичные данные:
public static int distStair;
}
// Статичные данные:
public static int distStair;
}
Обращаюсь так:
int a = Ladder.distStair;
пишет ошибку:
Expression denotes a `method group', where a `variable', `value' or `type' was expected
Обращаюсь так:
Ladder info;
...
int a = info.distStair;
пишет другую ошибку:
Static member `Ladder.distStair' cannot be accessed with an instance reference, qualify it with a type name instead
Правильный - первый вариант, но он ему не нравится. Причем с ненаследованным классом от MonoBehaviour (обычным или статическим) - все в порядке:
Так что ему надо?
Unity 3.3.0f4