需要类型“”的实例才能访问非静态成员“”
An instance of type '' is required to access non static member ' '
所以我理解这个问题,我想使我的 var 静态化。我明白了,但我做到了,但仍然有同样的问题。显然我忽略了一些东西....
Inventory.js
private static var emptySlots:int;
public static function get EmptySlots():int{
return emptySlots;
}
public static function set EmptySlots(value:int){
emptySlots = value;
}
然后我在这里调用那些函数....
Slot.js
if(IsEmpty()){
ChangeSprite(slotEmpty, slotHighlight);
Inventory.EmptySlots()++; // this is the line i try to reference
}
这是抛出的错误
Assets/Scripts/Slot.js(71,35): BCE0020: An instance of type 'Inventory' is required to access non static member 'EmptySlots'.
据我所知,Unity 脚本不支持静态属性。虽然它很旧,但请查看此讨论:http://forum.unity3d.com/threads/static-getter-setter.59621/
无论如何,如果是这样的话,正确的使用语法是:
Inventory.EmptySlots++;
所以,我想我会坚持使用 UnityScript 上的静态函数:
private static var emptySlots:int;
public static function getEmptySlots():int{
return emptySlots;
}
public static function setEmptySlots(value:int){
emptySlots = value;
}
和
if(IsEmpty()){
ChangeSprite(slotEmpty, slotHighlight);
Inventory.setEmptySlots(Inventory.getEmptySlots()+1);
}
所以我理解这个问题,我想使我的 var 静态化。我明白了,但我做到了,但仍然有同样的问题。显然我忽略了一些东西....
Inventory.js
private static var emptySlots:int;
public static function get EmptySlots():int{
return emptySlots;
}
public static function set EmptySlots(value:int){
emptySlots = value;
}
然后我在这里调用那些函数....
Slot.js
if(IsEmpty()){
ChangeSprite(slotEmpty, slotHighlight);
Inventory.EmptySlots()++; // this is the line i try to reference
}
这是抛出的错误
Assets/Scripts/Slot.js(71,35): BCE0020: An instance of type 'Inventory' is required to access non static member 'EmptySlots'.
据我所知,Unity 脚本不支持静态属性。虽然它很旧,但请查看此讨论:http://forum.unity3d.com/threads/static-getter-setter.59621/
无论如何,如果是这样的话,正确的使用语法是:
Inventory.EmptySlots++;
所以,我想我会坚持使用 UnityScript 上的静态函数:
private static var emptySlots:int;
public static function getEmptySlots():int{
return emptySlots;
}
public static function setEmptySlots(value:int){
emptySlots = value;
}
和
if(IsEmpty()){
ChangeSprite(slotEmpty, slotHighlight);
Inventory.setEmptySlots(Inventory.getEmptySlots()+1);
}