- Home /
Type 'Object' does not support slicing
Hi everyone. I'm doing the Robot Repair tutorial game in Unity3D Game Development by Example but I'm running into a problem early on and can't figure out what's causing it. I'm getting the error "Type 'Object' does not support slicing." but my code looks the same as the code in the book.
#pragma strict
var customSkin:GUISkin;
var cols:int = 4;
var rows:int = 4;
var totalCards:int = cols*rows;
var matchesNeededToWin:int = totalCards * 0.5;
var matchesMade:int = 0;
var cardW:int = 100;
var cardH:int = 100;
var aCards:Array; //Store the cards we create in this array
var aGrid:Array; //This array will keep track of the shuffled, dealt cards
var aCardsFlipped:ArrayList; //This array will sstore the cards the player flips over
var playerCanClick:boolean;
var playerHasWon:boolean = false;
function Start(){
playerCanClick = true;
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList();
for(var i=0;i<rows;i++){
aGrid[i]= new Array();
for(var j=0;j<cols;j++){
**aGrid[i][j] = new Card();**
}
}
}
function Update () {
}
function OnGUI(){
GUI.skin = customSkin;
GUILayout.BeginArea(Rect(0,0,Screen.width,Screen.height));
BuildGrid();
GUILayout.EndArea();
print("Building grid");
}
function BuildGrid(){
GUILayout.BeginVertical();
for(var i=0;i<rows;i++){
GUILayout.BeginHorizontal();
for(var j=0;j<cols;j++){
**var card:Object = aGrid[i][j];**
if(GUILayout.Button(Resources.Load(card.img),GUILayout.Width(cardW))){
Debug.Log(card.img);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
class Card extends System.Object
{
var isFaceUp:boolean = false;
var isMatched:boolean = false;
var img:String;
function Card(){
img = "model";
}
}
Answer by Eric5h5 · Jun 08, 2012 at 12:12 AM
You'd have to take #pragma strict out. Although it would be better not to use Array at all (or ArrayList either); a 2D array of type Card would be a lot better. Not really a great idea to use Resources.Load inside OnGUI either.
Your answer
Follow this Question
Related Questions
Making an item class in Unity. 1 Answer
Objects from Custom Classes 0 Answers
Custom JS class error - function is not a member of the class 2 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Trouble with an array of classes - Cannot implicitly convert type 4 Answers