Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Help Invetory Script

Help Invetory Script

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Help Invetory Script on Sun Nov 09, 2014 3:20 pm

FRAGSn111pezz


Member [Lv. 2]
Member [Lv. 2]
can some one help me i have a inventory with buttons but ones i pickup a item it stores it in the equipment tab not in the inventory here is my script
i think it is somehwere in line 82
my code :

Code:
private var invBackDrop : Texture2D;
private var equipmentBackDrop : Texture2D;
//Backdrops End

//Window Details
private var windowPosition : Vector2 = Vector2 (0,0);
private var windowSize : Vector2 = Vector2 (Screen.width, Screen.height);
private var windowRect : Rect = new Rect (windowPosition.x, windowPosition.y, windowSize.x, windowSize.y);
//Window Details End.

//GameObjects
private var player : GameObject;
private var gameManager : GameObject;
//GameObjects End

//Script Components
private var charMotor : CharacterMotor;
private var items : Items;
private var equipmentManager : EquipmentManager;
//Script Components End.

//Main Inventory List
var mainInventoryList : List.<ItemHandler> = new List.<ItemHandler>();

//This is for displaying the Inventory / Equipment screens.
private var display : boolean = false;

//This will be true when you click the button that says Equipment.
private var displayEquipScreen : boolean = false;

//This will be true when you click the button that says Inventory.
private var displayInventoryScreen : boolean = true;


function Start () {
    //Looks and Hides Cursor.
    Screen.lockCursor = true;
    Screen.showCursor = false;
   
    //Backdrops.
    invBackDrop = Resources.Load("Backgrounds/InventoryBackground", Texture2D);
    equipmentBackDrop = Resources.Load("Backgrounds/EquipmentBackground", Texture2D);
    //Backdrops End.
   
    //Finding GameObjects
    player = GameObject.FindGameObjectWithTag("Player");
    gameManager = GameObject.FindGameObjectWithTag("GameManager");
    //Findong GameObjects End.
   
    //Finding the Components
    charMotor = player.GetComponent(CharacterMotor);
    items = gameManager.GetComponent(Items);
    equipmentManager = gameManager.GetComponent(EquipmentManager);
    //Finding the Components End.
}

function Update () {
    //This will make it so when you press Tab that the inventory opens and the charater function stops.
    if(Input.GetKeyDown(KeyCode.Tab) && !display){
        display = true;
        Screen.lockCursor = false;
        Screen.showCursor = true;
        charMotor.enabled = false;
    }  else if(Input.GetKeyDown(KeyCode.Tab) && display){
        display = false;
        Screen.lockCursor = true;
        Screen.showCursor = false;
        charMotor.enabled = true;
    }
}

//This will handle displaying the buttons for our items
function OnGUI() {
  if(display){
      if(displayInventoryScreen){
        //Displays the inventory.
        GUI.DrawTexture(windowRect, invBackDrop, ScaleMode.StretchToFill);
        for(var i = 0; i < mainInventoryList.Count; i++) {
            if(GUI.Button(Rect(Screen.width / 2, Screen.height / 2 + (i * 25), 120, 20), GUIContent("  " + mainInventoryList[i].name, mainInventoryList[i].icon))); {
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Head) {
                    if(equipmentManager.equipmentList[0].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[0]);
                        equipmentManager.equipmentList[0] = mainInventoryList[i];
                        equipmentManager.equipmentList[0].equipped = true;
                    }
                      //If there is nothing is slot [0] then do this.
                      equipmentManager.equipmentList[0] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[0].equipped = true;
               
                } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Chest) {
                        if(equipmentManager.equipmentList[1].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[1]);
                        equipmentManager.equipmentList[1] = mainInventoryList[i];
                        equipmentManager.equipmentList[1].equipped = true;
                    }
                      //If there is nothing is slot [1] then do this.
                      equipmentManager.equipmentList[1] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[1].equipped = true;
                } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Gloves) {
                        if(equipmentManager.equipmentList[2].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[2]);
                        equipmentManager.equipmentList[2] = mainInventoryList[i];
                        equipmentManager.equipmentList[2].equipped = true;
                    }
                      //If there is nothing is slot [2] then do this.
                      equipmentManager.equipmentList[2] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[2].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Legs) {
                        if(equipmentManager.equipmentList[3].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[3]);
                        equipmentManager.equipmentList[3] = mainInventoryList[i];
                        equipmentManager.equipmentList[3].equipped = true;
                    }
                      //If there is nothing is slot [3] then do this.
                      equipmentManager.equipmentList[3] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[3].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Feet) {
                        if(equipmentManager.equipmentList[4].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[4]);
                        equipmentManager.equipmentList[4] = mainInventoryList[i];
                        equipmentManager.equipmentList[4].equipped = true;
                    }
                      //If there is nothing is slot [4] then do this.
                      equipmentManager.equipmentList[4] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[4].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.RightHand) {
                        if(equipmentManager.equipmentList[5].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[5]);
                        equipmentManager.equipmentList[5] = mainInventoryList[i];
                        equipmentManager.equipmentList[5].equipped = true;
                    }
                      //If there is nothing is slot [5] then do this.
                      equipmentManager.equipmentList[5] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[5].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.LeftHand) {
                        if(equipmentManager.equipmentList[6].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[6]);
                        equipmentManager.equipmentList[6] = mainInventoryList[i];
                        equipmentManager.equipmentList[6].equipped = true;
                    }
                      //If there is nothing is slot [6] then do this.
                      equipmentManager.equipmentList[6] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[6].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.Neckless) {
                        if(equipmentManager.equipmentList[7].equipped) {
                        mainInventoryList.Add(equipmentManager.equipmentList[7]);
                        equipmentManager.equipmentList[7] = mainInventoryList[i];
                        equipmentManager.equipmentList[7].equipped = true;
                    }
                      //If there is nothing is slot [7] then do this.
                      equipmentManager.equipmentList[7] = mainInventoryList[i];
                      mainInventoryList.RemoveAt(i);
                      equipmentManager.equipmentList[7].equipped = true;
                  } else 
                if(mainInventoryList[i].itemType == mainInventoryList[i].itemType.HealingItem) {
                    Debug.Log("This is where you add the functionality of healing items.");
                    [You must be registered and logged in to see this link.]
                }
            }
           
        }
      }
          if(displayEquipScreen) {
          GUI.DrawTexture(windowRect, equipmentBackDrop, ScaleMode.StretchToFill);
            //Helm
            //This will create a button if the helmet is equipped.
            if(  equipmentManager.equipmentList[0].equipped) {
                if(GUI.Button(Rect(Screen.width / 2, (Screen.height / 2) - 100, 120, 20), GUIContent (" " + equipmentManager.equipmentList[0].name, equipmentManager.equipmentList[0].icon))) {
                      mainInventoryList.Add(equipmentManager.equipmentList[0]);
                      equipmentManager.equipmentList[0].equipped = false;
                      equipmentManager.update = true;

                }
            }
          }
          //This handles the switching between the Equipment screen and the Inventory screen.
          if(GUI.Button(Rect(Screen.width / 1.25, (Screen.height / 2) - 50, 120, 25), "Equipment")) {
              displayEquipScreen = true;
              displayInventoryScreen = false;
          }
          if(GUI.Button(Rect(Screen.width / 1.25, (Screen.height / 2) - 80, 120, 25), "Inventory")) {
              displayEquipScreen = false;
              displayInventoryScreen = true;
          }
       
  }
 
}

View user profile

2 Re: Help Invetory Script on Sun Nov 09, 2014 3:21 pm

FRAGSn111pezz


Member [Lv. 2]
Member [Lv. 2]
after the for loop at MainInventory[i]

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum