Exemple #1
0
    void OnGUI()
    {
        // Resize GUI
        Vector2 resizeRatio = new Vector2((float)Screen.width / nativeWidth, (float)Screen.height / nativeHeight);

        GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(resizeRatio.x, resizeRatio.y, 1.0f));

        // Custom GUI skin
        GUI.skin = myStyle;

        if (networkView.isMine)
        {
            // If the player clicks on the button, the inventory window will toggle
            if (GUI.Button(new Rect(nativeWidth - 450, nativeHeight - 50, 40, 40), bagIcon))
            {
                soundEffects.PlayAudio(6);
                ToggleBag();
            }

            if (showBag == true)
            {
                GUI.Box(boxRect, bagName);

                int width  = 0;
                int height = 0;
                int k      = 0;

                // Create inventory as a 3x3 array of buttons
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (j == 0 && i > 0)
                        {
                            height += 65;
                            width   = 0;
                        }
                        width += 65;

                        invButton[i, j] = new Rect(nativeWidth - 615 + width, nativeHeight - 275 + height, 50, 50);

                        if (GUI.Button(new Rect(invButton[i, j]), defaultTextureSlot[k]))
                        {
                            // If the player clicks on a slot with the left mouse button the effect of the potion
                            // will take place.
                            if (Event.current.button == 0)
                            {
                                soundEffects.PlayAudio(7);

                                itemCounter--;
                                texInv = defaultTextureSlot[k];
                                itemEf.Effect();
                                defaultTextureSlot[k] = null;
                                fullBag = false;
                            }
                            // If the player clicks on a slot with the right mouse button the item will be "ready" to sell
                            else if (Event.current.button == 1)
                            {
                                soundEffects.PlayAudio(4);

                                itemSelecredRight = true;
                                texInv            = defaultTextureSlot[k]; // The texture clicked will be stored in a temp variable
                                temp = k;                                  // Store the index of the array to see which button was pressed
                            }
                        }
                        k++;
                    }
                }
                GUI.DrawTexture(coinRect, coinTex);
                GUI.Label(goldLabel, "GOLD: " + CountdownTimer.myGold.ToString("f0"));
            }
        }
    }