Search Unity

Simple Inventory for imported FBX.

Discussion in 'Scripting' started by Slyrfecso1, Aug 3, 2015.

  1. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi,

    I would like to make simple inventory with imported FBX models.
    I have created the inventory script, but I don't know how can I add models to inventory.
    I have seen many tutorials and tried inventory systems, but I didn't solved.

    Need I make icons the my models?
    Need I make prefabs for all imported models?

    If anyone have time to help me, than I would be happy.
    Thanks.


    Item.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Item {
    6.  
    7.     public string itemName;
    8.     public int itemID;  
    9.     public string itemDesc;
    10.     public Texture2D itemIcon;
    11.     public ItemType itemType;
    12.  
    13.     public enum ItemType {
    14.         Classic,
    15.         Stark,
    16.         AlexStandard,
    17.         Szekrény
    18.     }
    19. }


    ItemDatabase.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class ItemDatabase : MonoBehaviour {
    6.     public List<Item> items = new List<Item> ();
    7.  
    8. }
    9.  


    Inventory.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5.  
    6.  
    7. public class Inventory : MonoBehaviour {
    8.  
    9.     public bool isToggled = false;
    10.  
    11.     //public List<PrefabList> inventory = new List<PrefabList>();
    12.  
    13.  
    14.     /****************************/
    15.  
    16.     private static int invID = 01;
    17.     private Rect invWindow = new Rect(50,50, 450, 370);
    18.     private int inventoryRows = 4;
    19.     private int inventoryCols = 4;
    20.  
    21.     /****************************/
    22.  
    23.     private int buttonWidth = 100;
    24.     private int buttonHeight = 75;
    25.  
    26.  
    27.     /*****TEMP BUTTONS CONTROL****/
    28.  
    29.  
    30.  
    31.  
    32.     void Start () {
    33.    
    34.    
    35.    
    36.  
    37.     }
    38.  
    39.     void Update () {
    40.    
    41.  
    42.         if(Input.GetKeyDown(KeyCode.I))
    43.         {
    44.             isToggled = !isToggled;
    45.         }
    46.    
    47.    
    48.     }
    49.  
    50.  
    51.    
    52.     void OnGUI()
    53.     {
    54.    
    55.         if(isToggled == true)
    56.         {
    57.             drawInventory();
    58.         }
    59.    
    60.     }
    61.  
    62.  
    63.  
    64.  
    65.  
    66.     public void drawInventory()
    67.     {
    68.         invWindow = GUI.Window(invID, invWindow, inventoryWindow, "TERMÉKPALETTA");
    69.     }
    70.  
    71.  
    72.  
    73.  
    74.  
    75.     public void inventoryWindow(int id)
    76.     {
    77.         GUI.BeginGroup(new Rect(invWindow.width, 20, 240, 370), "");
    78.         GUI.Box(new Rect(0, 0, 240, 370), "");
    79.  
    80.            
    81.         GUI.EndGroup();
    82.         GUI.BeginGroup(new Rect(10, 20, 430, 330), "");
    83.    
    84.         GUI.skin = null;
    85.         GUI.Box(new Rect(0,0,430,330), "");
    86.         for(int x = 0; x<inventoryCols; x++)
    87.         {
    88.             for(int y = 0; y < inventoryRows; y++)
    89.             {
    90.                 GUI.Button(new Rect(15 + (x * buttonWidth), 15 + (y * buttonHeight), buttonWidth, buttonHeight), "");
    91.             }
    92.         }
    93.         GUI.EndGroup();
    94.         GUI.DragWindow();
    95.    
    96.     }
    97.  
    98.  
    99. }
    100.  
     
    Last edited: Aug 3, 2015