- Home /
Unity thinks one of my variables is a System.type
I am creating an inventory system and I need to find out the item type of an item but in my if statement it keeps thinking that one of my variables is a System.type when it is not it is in line 106. This is what it says : Assets/Scripts/Inventory/Inventory.js(106,83): BCE0051: Operator '==' cannot be used with a left hand side of type 'System.Type' and a right hand side of type 'Item.ItemGroup'.
import System.Collections.Generic;
//Backdrops
private var invBackDrop : Texture2D;
private var equipBackDrop : Texture2D;
//Backdrops end
//Windows detail
private var windowPosition : Vector2 = Vector2(0,0);
private var windowSize : Vector2 = Vector2(Screen.width, Screen.height);
//Windows detail end
private var windowRectangle : Rect = new Rect(windowPosition.x, windowPosition.y, windowSize.x, windowSize.y);
//GameObjects
var player : GameObject;
private var gameManager : GameObject;
//GameObjects End
//Script Components
//var playerMotor : UnityStandardAssets.Characters.FirstPerson.FirstPersonController;
private var items : ItemCreator;
private var equipmentManager : EquipmentManager;
//Script Components End
//Main Inventory List
var MainInventoryList : List.<Item> = new List.<Item>();
private var Group : Item.ItemGroup;
//Main Inventory List End
//displaying screens
private var display : boolean = false;
//When clicking buttons to display equipment screen
private var displayEquipScreen : boolean = false;
//When clicking butttons to display inventory screen
private var displayInvScreen : boolean = true;
// Use this for initialization
function Start ()
{
Screen.lockCursor = true;
Cursor.visible = false;
invBackDrop = Resources.Load("Background/InventoryBackground", Texture2D);
equipBackDrop = Resources.Load("Background/EquipmentBackground", Texture2D);
player = GameObject.FindGameObjectWithTag("Player");
gameManager = GameObject.FindGameObjectWithTag("GameManager");
items = gameManager.GetComponent(ItemCreator);
equipmentManager = gameManager.GetComponent(EquipmentManager);
//playerMotor = player.GetComponent(FirstPersonController);
}
// Update is called once per frame
function Update ()
{
//when you press e it will bring up inventory screen
if(Input.GetKeyDown(KeyCode.E) && !display)
{
display = true;
Screen.lockCursor = false;
Cursor.visible = true;
}else if (Input.GetKeyDown(KeyCode.E) && display)
{
display = false;
Screen.lockCursor = true;
Cursor.visible = false;
}
}
function OnGUI()
{
if(display)
{
if(displayInvScreen)
{
if(GUI.Button(Rect(Screen.width / 2, Screen.height / 2 + 50, 120, 20), "Equipment"))
{
displayEquipScreen = true;
displayInvScreen = false;
}
GUI.DrawTexture(windowRectangle, invBackDrop, ScaleMode.StretchToFill);
for(var x = 0; x < MainInventoryList.Count; x++)
{
if(GUI.Button(Rect(Screen.width / 2 - 350, Screen.height / 2 - (x * 50), 90, 50), GUIContent(" " + MainInventoryList[x].name , MainInventoryList[x].icon)))
{
106: if(MainInventoryList[x].ItemGroup == Group.light)
{
}
//if(MainInventoryList[x].ItemGroup == MainInventoryList[x].ItemGroup.light)
//{
// print("We have reached the equipment stage");
//This will make it so that when you equip an item to a slot that is already full then it will equip the item and get the other item and put it in the main Inventory
// if(equipmentManager.equipmentList[0].equipped)
// {
// MainInventoryList.Add(equipmentManager.equipmentList[0]);
// equipmentManager.equipmentList[0] = MainInventoryList[x];
// equipmentManager.equipmentList[0].equipped = true;
// }
//if there is nothing there do this
// equipmentManager.equipmentList[0] = MainInventoryList[x];
// MainInventoryList.RemoveAt(x);
// equipmentManager.equipmentList[0].equipped = true;
//}else if(MainInventoryList[x].ItemGroup.food)
//{
//}
}
}
}
if(displayEquipScreen)
{
GUI.DrawTexture(windowRectangle, equipBackDrop, ScaleMode.StretchToFill);
if(GUI.Button(Rect(Screen.width / 2, Screen.height / 2 - 80, 120, 20), "Inventory"))
{
displayEquipScreen = false;
displayInvScreen = true;
}
}
if(GUI.Button(Rect(Screen.width / 2, Screen.height / 2 + 50, 120, 20), "Equipment"))
{
displayEquipScreen = true;
displayInvScreen = false;
}
}
}
I added a tag to bce0051 to allow you to look at existing questions and answers.
Your comparison is wrong I think. I think it should be : if($$anonymous$$ainInventoryList[x].ItemGroup.light == Group.light)
Follow this Question
Related Questions
Why can't won't my if then statements work? 1 Answer
Problem with if statements relating to images 1 Answer
Distance sensor 1 Answer
why != is different from var1 = !var2? 2 Answers