It is not possible to invoke an expression of type 'UnityEngine.Texture[]'.

Im Trying to make a inventory System But the Texture Does Not Want To Change

#pragma strict

var arrayGrid = 0;
static var inventoryNewItemAdded = -1;
var theInventory : Inventory_GUI;
var theTextures : Player_Inventory;

//Icons
var blankIcon : Texture;
var theNewItem : Texture;

function Start () {
	theInventory = GetComponent(Inventory_GUI);
	theTextures = GetComponent(Player_Inventory);
}

function newItem () {
	if (Inventory_Add_Item.inventoryNewItemAdded> -1) {
		theNewItem = theTextures.itemTexture(Inventory_Add_Item.inventoryNewItemAdded);
		if (arrayGrid < theInventory.gridsTexture.length)  {
			if (theInventory.gridsTexture[arrayGrid].image == blankIcon)  {
				//adding Item
				theInventory.gridsTexture[arrayGrid].image = theNewItem;
				arrayGrid = 0;
				Inventory_Add_Item.inventoryNewItemAdded = -1;
			}
			else if (theInventory.gridsTexture[arrayGrid].image != blankIcon)  {
				arrayGrid += 1;
			}
		}
	}
}

#pragma strict

// Items
static var itemID : String[] = ["9mm Ammo", "9mm Pistol", "Arrow", "Baton", "Battery", "Long Bow","Boxers",
								"Cross Bow", "File", "Flash Light", "Hat", "ID Badge", "Jumper", "Knife",
								"M4 Ammo", "M4", "Metal", "Rock", "Shiv", "Shoes", "Shotgun", "Shotgun Shells",
								"Socks", "Spoon", "String", "Gards Knife", "Uniform", "Police Uniform", "Wire",
								"Wood", "Can"];
static var itemsPlayerAmount : int[] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
										0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var itemTexture = new Texture [Player_Inventory.itemID.length];

function Start () {
	var textures : Object[] = Resources.LoadAll("Item_Icons", Texture2D);
	for (var i = 0; i < textures.length; i++)		
	{
		itemTexture _= textures*;*_

* }*
* }*

Please format this using 10101 button

–

Dont Know What That Means

–

I did it. Next time, select your code when you're writing your question, and hit the button with 1 and 0 in the toolbar.

–

Thanks do you know what's wrong with the code

–

You don't even say what line is causing the error, it should be written in the logs window. I suppose it is : var itemTexture = new Texture [Player_Inventory.itemID.length]; And I think the problem is because of Player_Inventory.itemID.length, try to put "10" instead for example and see if there still is the error.

–

1 Answer

1

It’s probably the line 19:

    theNewItem = theTextures.itemTexture(Inventory_Add_Item.inventoryNewItemAdded);

Since “itemTexture” is a Texture array, you probably want this instead

    theNewItem = theTextures.itemTexture[Inventory_Add_Item.inventoryNewItemAdded];

Note: I used the indexing-brackets , not the invocation brackets ().

I had the same problem. Googled a bit more. Found the solution on [Stackoverflow][1] To summarize: Check the pivot setting at the top of your editor. Mine was set to: "Center" and "Local". You should set it to: "Pivot" and "Local". Check the link for screenshots. Hope it helps [1]: http://stackoverflow.com/questions/22693362/unity-objects-not-rotating-around-pivot-point

–