统一的库存和制作系统?

时间:2014-05-06 01:31:00

标签: unity3d unityscript inventory

我正在创造一个团结的开放世界生存游戏。我已经制作了一个清单并尝试制作一个制作系统。我想知道是否有人有他们可以分享的制作系统示例,或者帮我解决一些问题。我的脚本在下面,我的问题也是如此。

  1. 我正在制作一个制作系统和库存,其中包含一系列用于清单的网格(我已经这样做了)
  2. 您可以在左侧制作的项目列表,如果您点击其中一个项目,并且在您的库存中有适当的材料,那么它将带走旧项目并为您提供一个新项目。 (我在这个问题上遇到了麻烦)
  3. 所以我在我的代码中添加了一些Debug.Log消息,并且我得到了所有这些消息,在属性检查器中,金额也发生了变化。当我点击工艺按钮时,它不会带走并添加纹理。我根本不确定如何做到这一点,因为我对java脚本相当新,我很难制作新代码或知道如何/何时使用它(是的,我已经从YouTube上的一些教程可以做到这一点。)

    我认为我只需要这样做就可以添加项目的纹理,但是我的代码部分太复杂了,无法在我的级别上理解100%,我更了解60-75%以了解最新情况。无论如何,这里是代码的一部分,我认为纹理显示,但我不知道如何使它们消失。

        if(Input.GetKeyDown(KeyCode.Tab))
        {
            InventoryOn = !InventoryOn;
        }
        if(AddingItems == true)
        {
             Debug.Log("AddItemTrue");
             if(NewTexture[InventoryGrid] == Blank)
             {
                   NewTexture[InventoryGrid]=item;
                   AddingItems = false;
                   InventoryGrid = 0;
             }
              else if(NewTexture[InventoryGrid] != Blank)
              {
                  InventoryGrid += 1;
                  Debug.Log("AddItem");
              }
        }
    
    
    
       if(Clicks == 0)
       {
           MouseTexture = Blank;
       }
    
       if(Clicks == 1)
       {
           MouseTexture = NewTexture[GridNumber];
           PrevTexture = GridNumber;                                            
       }
    
       if(Clicks == 2)
       {
           if(NewTexture[GridNumber] != Blank)
           {
               Clicks = 1;
           }
    
           if(NewTexture[GridNumber] == Blank)
           {       
               NewTexture[GridNumber] = MouseTexture;
               NewTexture[PrevTexture] = Blank;
               Clicks = 0;
           }
      }
    

    我想我最后需要将它添加到Craft2函数的末尾,但我不知道如何做到这一点并使旧纹理在制作时消失。我已将下面的整个脚本放在下面供您查看和检查,以及我对要收集的项目放置的ItemCollection脚本。

    这是库存。

    #pragma strict
    
    
    var Ammount : int[] = [0,0,0,0];
    var ItemTransform : Transform[];
    var NewTexture : Texture[];
    var AllTextures : Texture[];
    var InventoryGrid : int;
    var GridNumber : int;
    var AddingItems = false;
    var MouseTexture : Texture;
    var Change = false;
    var item : Texture;
    var ItemNumber : int;
    var Crafting : boolean[];
    var CraftingNumber : int;
    private var TextureNumber : int;
    private var PrevTexture : int;
    private var HotBarActive : int = 35;
    private var ItemID : String[] = ["Wood","Stone","Metal Ore","Iron"];
    private var Blank : Texture;
    private var Clicks : int;
    // private var PrevNo : int;
    private var InventoryOn = false;
    private var JustClicked = false;
    
    
    
    
    function ADDTexture(ItemTexture : Texture)
    {
        item = ItemTexture;
        AddingItems = true;
    }
    
    
    
    function ADD(material : int)
    {
       ItemNumber = material;
       Ammount[material] +=1;
    }
    
    
    function OnGUI()
    {
    if(InventoryOn == true)
         {
         GUI.Label(Rect(Input.mousePosition.x - 25, Screen.height - Input.mousePosition.y -       25 ,100,50),MouseTexture);
    
         GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height /2 - 300,800,600));
    
         if(GUI.Button(Rect(100,50,50,50),NewTexture[0]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 0;       
         }
         if(GUI.Button(Rect(150,50,50,50),NewTexture[1]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 1;       
         }
         if(GUI.Button(Rect(200,50,50,50),NewTexture[2]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 2;  
         }
         if(GUI.Button(Rect(250,50,50,50),NewTexture[3]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 3;  
         }
         if(GUI.Button(Rect(300,50,50,50),NewTexture[4]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 4;  
         }
         if(GUI.Button(Rect(350,50,50,50),NewTexture[5]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 5;  
         }
         if(GUI.Button(Rect(400,50,50,50),NewTexture[6]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 6;  
         }
         if(GUI.Button(Rect(100,100,50,50),NewTexture[7]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 7;  
         }
         if(GUI.Button(Rect(150,100,50,50),NewTexture[8]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 8;  
         }
         if(GUI.Button(Rect(200,100,50,50),NewTexture[9]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 9;  
         }
         if(GUI.Button(Rect(250,100,50,50),NewTexture[10]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 10; 
         }
         if(GUI.Button(Rect(300,100,50,50),NewTexture[11]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 11; 
         }
         if(GUI.Button(Rect(350,100,50,50),NewTexture[12]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 12; 
         }
         if(GUI.Button(Rect(400,100,50,50),NewTexture[13]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 13; 
         }
         if(GUI.Button(Rect(100,150,50,50),NewTexture[14]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 14; 
         }
         if(GUI.Button(Rect(150,150,50,50),NewTexture[15]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 15; 
         }
         if(GUI.Button(Rect(200,150,50,50),NewTexture[16]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 16; 
         }
         if(GUI.Button(Rect(250,150,50,50),NewTexture[17]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 17; 
         }
         if(GUI.Button(Rect(300,150,50,50),NewTexture[18]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 18; 
         }
         if(GUI.Button(Rect(350,150,50,50),NewTexture[19]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 19; 
         }
          if(GUI.Button(Rect(400,150,50,50),NewTexture[20]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 20; 
         }
         if(GUI.Button(Rect(100,200,50,50),NewTexture[21]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 21; 
         }
         if(GUI.Button(Rect(150,200,50,50),NewTexture[22]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 22; 
         }
         if(GUI.Button(Rect(200,200,50,50),NewTexture[23]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 23; 
         }
         if(GUI.Button(Rect(250,200,50,50),NewTexture[24]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 24; 
         }
         if(GUI.Button(Rect(300,200,50,50),NewTexture[25]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 25; 
         }
         if(GUI.Button(Rect(350,200,50,50),NewTexture[26]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 26; 
         }
         if(GUI.Button(Rect(400,200,50,50),NewTexture[27]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 27; 
         }
         if(GUI.Button(Rect(100,250,50,50),NewTexture[28]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 28; 
         }
         if(GUI.Button(Rect(150,250,50,50),NewTexture[29]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 29; 
         }
         if(GUI.Button(Rect(200,250,50,50),NewTexture[30]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 30; 
         }
         if(GUI.Button(Rect(250,250,50,50),NewTexture[31]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 31; 
         }
         if(GUI.Button(Rect(300,250,50,50),NewTexture[32]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 32; 
         }
         if(GUI.Button(Rect(350,250,50,50),NewTexture[33]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 33; 
         }
         if(GUI.Button(Rect(400,250,50,50),NewTexture[34]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 34; 
         }
    
         if(GUI.Button(Rect(400,350,50,50),NewTexture[40]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 40;
         }
    
         if(GUI.Button(Rect(450,350,50,50),NewTexture[41]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 41;
         }
    
         if(GUI.Button(Rect(500,350,50,50),NewTexture[42]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 42;
         }
    
         if(GUI.Button(Rect(600,350,50,50),NewTexture[43]))
         {
                  if(MouseTexture == Blank)
                  {
                      if(NewTexture[43] !=Blank)
                      {
                          JustClicked = true;
                          NewTexture[40] = Blank;
                          NewTexture[41] = Blank;
                          NewTexture[42] = Blank;
                      }
                 Change = true;
                 Clicks += 1;
                 GridNumber = 43;
                 }
             }
             if(GUI.Button(Rect(200,500,80,30),"Craft Item")
             {
             Craft2 ();
                 Debug.Log("button");
         }
    
             Debug.Log(Clicks);
    
             GUI.EndGroup();
         }
         if(GUI.Button(Rect(100,550,65,65),NewTexture[35]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 35;
         }
         if(GUI.Button(Rect(165,550,65,65),NewTexture[36]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 36;
         }
         if(GUI.Button(Rect(230,550,65,65),NewTexture[37]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 37;
         }
         if(GUI.Button(Rect(295,550,65,65),NewTexture[38]))
         {
             Change = true;
             Clicks += 1;
             GridNumber = 38;
         }
         if(GUI.Button(Rect(360,550,65,65),NewTexture[39]))
         {
         Change = true;
         Clicks += 1;
         GridNumber = 39;
         }
    }
    
    
    
    
    function Update () 
       {         
       if(Input.GetKeyDown(KeyCode.Alpha1))
       {
           HotBarActive = 35;
       }
       if(Input.GetKeyDown(KeyCode.Alpha2))
       {
           HotBarActive = 36;
       }
       if(Input.GetKeyDown(KeyCode.Alpha3))
       {
           HotBarActive = 37;
       }
       if(Input.GetKeyDown(KeyCode.Alpha4))
       {
           HotBarActive = 38;
       }
       if(Input.GetKeyDown(KeyCode.Alpha5))
       {
           HotBarActive = 39;
       }
    
       if(NewTexture[HotBarActive] == AllTextures[TextureNumber])
       {
           PrevTexture = TextureNumber;
           ItemTransform[TextureNumber].active = true;
       }
    
       if(NewTexture[HotBarActive] != AllTextures[TextureNumber])
       {
           ItemTransform[PrevTexture].active = false;
           TextureNumber += 1;
           if(TextureNumber >= AllTextures.Length)
           {
               TextureNumber = 0;
           }
       }
    
      if(Input.GetKeyDown(KeyCode.Tab))
      {
          InventoryOn = !InventoryOn;
      }
      if(AddingItems == true)
      {
          Debug.Log("AddItemTrue");
          if(NewTexture[InventoryGrid] == Blank)
          {
              NewTexture[InventoryGrid]=item;
              AddingItems = false;
              InventoryGrid = 0;
          }
          else if(NewTexture[InventoryGrid] != Blank)
          {
              InventoryGrid += 1;
              Debug.Log("AddItem");
          }
       }
    
    
    
       if(Clicks == 0)
       {
           MouseTexture = Blank;
       }
    
       if(Clicks == 1)
       {
           MouseTexture = NewTexture[GridNumber];
           PrevTexture = GridNumber;                                            
       }
    
       if(Clicks == 2)
       {
           if(NewTexture[GridNumber] != Blank)
           {
               Clicks = 1;
           }
           if(NewTexture[GridNumber] == Blank)
           {                    
               NewTexture[GridNumber] = MouseTexture;
               NewTexture[PrevTexture] = Blank;
               Clicks = 0;
           }
    }
    }
    function Craft2 ()
    {
    if(Crafting[2] == true)
        {
            Debug.Log("Ammount");
        if(Ammount[0] >=2 && Ammount[1] >=1)
            {
                Ammount[0]-=2;
                Ammount[1]-=1;
                Ammount[2]+=1;
                Debug.Log("Ammount1");
                Crafting[2] = false;
            }
        }
    }
    

    这是我在我想要收集的项目上的ItemCollection脚本。

    #pragma strict
    
    var Player : Transform;
    var material : int;
    var Static : int = 1;
    var ItemTexture : Texture;
    var NewText : Texture[];
    var Colider : Collider;
    
    function Start()
    {
        ItemTexture = NewText[material];
    }
    
    function Mining(Character : Transform)
    {
        Player = Character;
        Player.SendMessage("ADD",material);
        Player.SendMessage("ADDTexture",ItemTexture);
        Static -=1;
    }
    
    function Update()
    {
        if(Static <=0)
        {
            Destroy(gameObject);
        }
    }
    

    一切正常,除非它没有将纹理添加到我的广告资源中,也没有将它们删除,但它确实会更改属性检查器中的Ammount变量。

0 个答案:

没有答案