2013-08-25 5 views
0

의 배열을 통해 클래스 변수에 액세스 할 수 없습니다 것은 여기 내 클래스객체 (unityscript/유니티)

public class ItemClass extends System.ValueType 
{ 
    public var itemTexture : Texture2D; 
    public var descriptionTexture : Texture2D; 

    public function ItemClass (item:Texture2D, desc:Texture2D) 
    { 
     itemTexture = item; 
     descriptionTexture = desc; 
     //GUI.DrawTexture(Rect(179, 140, 200, 202), attHighlight4); 
    } 
} 

것은 여기에 내가 itemArray에 액세스하려고하면 내 배열

var Test = new ItemClass(Axe, AxeDescription); 
public var itemArray = new ArrayList(); 
itemArray.Add(Test); 

[0]. itemTexture Unity는 itemTexture가 'Object'의 멤버가 아니라고 알려줍니다.

itemTexture에 액세스하는 구문을 찾고 있습니다.

ArrayListsWhich Kind Of Array Or Collection Should I Use?가 '객체'가 포함 :

답변

1

당신은 도움이 위키 페이지를 찾을 수 있습니다. 항목을 다시 ArrayList에서 검색 할 때 런타임 또는 컴파일러에서 해당 항목의 원래 유형이 확실하지 않습니다. 당신은 다음과 같은 항목에 대해 좀 더 명시 적 타입 힌트를 제공해야합니다

var myItem : ItemClass = itemArray[0] 
var myTexture   = myItem.ItemTexture 

당신은 위키 페이지에서 다루는 이유, 대신 List<>를 사용하는 것이 좋습니다.

+0

아, 감사합니다. 저는 Javascript에 들어가는 C++ 프로그래밍입니다. C++에서 단순한 많은 것들이 조금 더 많은 작업이되고 있습니다. –