- Home /
 
Inventory question
I have been watching this unity tutorial on Youtube where you learn how to make an inventory. Everything has been going well until I watched Episode 7. I just can't understand what I did wrong. I can't see any difference with his script and my script. http://www.youtube.com/watch?v=rJZrhEl5V58&list=PLxLNqnnCshwm9ayxqMpeWH4P1SLzrN92- I know which part of the script is wrong, but I posted the whole script anyway.
 import System.Collections.Generic;
 
 //holding all our items
 var items : Item[];
 //inventory
 var MainInventory : List. <Item> = new List.<Item>();
 
 //Equip menu ( 0=hat, 1=helmet, 2= shoulders, 3=gloves, 4=pants, 5=boots, 6=ring, 7= neckless)
 var EquipMenu : Item[];
 
 function Start () {
     
     MainInventory.Add(items[0]);
     MainInventory.Add(items[1]);
 }
 
 
 function OnGUI () {
     
     for (var x = 0; x < MainInventory.Count; x++) {
     
         if(GUI.Button(Rect(Screen.width/2, Screen.height/ 2 + ( 20 * x),100,20), GUIContent ( MainInventory[x].Name,
         "Stanima: " + MainInventory[x].Stamina + "\n" +
         "Power: " + MainInventory[x].Power + "\n" +
         "Attack Speed: " + MainInventory[x].attackSpeed + "\n" +
         "Rarity: " + MainInventory[x].rarity))) {
         
             if (MainInventory[x].itemType == MainInventory[x].itemType.helmet) {
                      
                 EquipMenu[0] = MainInventory[x];
                 MainInventory.RemoveAt(x);
                 }
                 else if (MainInventory[x].itemType == MainInventory[x].itemType.shoulders) { 
                     EquipMenu[1] = MainInventory[x];
                     MainInventory.RemoveAt(x);        
                 }                                                
         }
         GUI.Label(Rect(Screen.width/2 + 70, Screen.height/ 2 + ( 20 * x),300,300), GUI.tooltip);
     }
     for (var y = 0; y < EquipMenu.length; y++) {
         
         if (EquipMenu[y] != null);
             
             if(GUI.Button(Rect(Screen.width/2 - 150, Screen.height/ 2 + ( 20 * y),100,20), "" + EquipMenu[y].name)) {
                 
                 MainInventory.Add(EquipMenu[y]);
                 EquipMenu[y] = null;
                 }
             }
         }
 
               Note: I know that I did the second script right because it otherwise wouldn't work in the previous videos in the tutorial if I wrote it wrong.
No, this is the error: Assets/Inventory/Inventory.js(22,101): BCE0004: Ambiguous reference 'constructor': UnityEngine.GUIContent.constructor(UnityEngine.Texture, String), UnityEngine.GUIContent.constructor(String, String), UnityEngine.GUIContent.constructor(String, UnityEngine.Texture).
Well, that is a compile error, and it makes sense if $$anonymous$$ainInventory[x].Name is a String and not a Texture. That error is telling you everything you need to know. You need to pass a Texture, not a String, as the first parameter of GUIContent().
Answer by Oribow · Jul 04, 2013 at 11:53 AM
Translate import System.... to using System.... in the first line
Your answer
 
             Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
AI enemy scripting help 1 Answer
Inventory, simple and easy 5 Answers
Scripting error #2! 2 Answers
Issues with Inventory script 0 Answers