Beginning 3d game development, chapter 12.

While trying to create the inventory grid in chapter 12 of Sue Blackman’s book, I’m hitting the error ‘guiTexture’ is not a member of ‘Object’, and for the life of me, I can’t figure out where I’ve messed it.
The code it’s having a fit about is:

function InventoryGrid () {
	var xPos = -startPos - iconSize/2;//adjust column offset start position according to icon
	var spacer = startPos - iconSize; //caculate the spacer size
	var iLength = currentInventoryObjects.length;//length of the array
	for (var k = 0; k < iLength; k = k + 3) {
		//row 1
		var yPos = startPos - iconSize/2;
		currentInventoryObjects[k].guiTexture.pixelInset = Rect(xPos, yPos, iconSize,iconSize);
		//row 2
		yPos = yPos - iconSize - spacer;
		if (k + 1 < iLength)currentInventoryObjects[k+1].guiTexture.pixelInset = Rect(xPos,yPos, iconSize,iconSize);
		//row 3
		yPos = yPos - iconSize - spacer;
		if (k + 2 < iLength)currentInventoryObjects[k+2].guiTexture.pixelInset = Rect(xPos,yPos, iconSize,iconSize);
		
		xPos = xPos + iconSize + spacer;//update column position for the next group
	}//close the for loop
	
}//close the function

Compared it to the code from the examples in the download file, and still can’t find anything.

[Disclaimer: primarily use C# for Unity]

GameObject has a field named GUITexture. Your error is telling you that you have an Object – not a GameObject – and that Objects don’t have guiTextures.

If you look at the line: currentInventoryObjects[k].guiTexture then currentInvObj must be the Object it’s complaining about. Somewhere else in the code, when you declare and fill currentInvObj, you must be saying it’s only an Object. Change to a GameObject and Unity should be a lot happier.

Sorry for the late answer, but I read your quote right now, cause I 've been working and I reached the chapter 12 recently on this book project.

I’ve tried, tried, tried…and I have created this bit of code:

//add the following in the variables section


var inventoryObjects : GUITexture[]; //to be filled in the inspector with inventory icons

private var currentInventory Objects = new Array();


//add the following in the Start() function section


//get the inventory icons declared in the inspector by the "inventoryObjects" builtin array
//and put them in the "currentInventoryObjects" javascript array

for( var iObject in inventoryObjects )

{

	if( iObjects.GetComponent( Interactor ).Instantiate == 1 )

	{
            
		//create a temporary array to store the iObject element

		var array = new array( iObject );

		
		//add the only element stored in the array (array[0])

		currentInventoryObjects.Add( array[0] );

	}

}


InventoryGrid();


//swap the following in the inventoryGrid() function


currentInventoryObjects[k].guiTexture.pixelInset = Rect(...

currentInventoryObjects[k+1].guitexture.pixelInset...

currentInventoryObjects[k+2].guitexture.pixelInset...


//respectively to:


var objRow1 : GUITexture = currentInventoryObjects[k];
objRow1.guiTexture.pixelInset = Rect(...


var objRow2 : GUITexture = currentInventoryObjects[k+1];

objRow2.guiTexture.pixelInset = Rect(...


var objRow3 : GUITexture = currentInventoryObjects[k+2];

objRow3.guiTexture.pixelInset = Rect(...