Search Unity

GUI button does not display texture

Discussion in 'Scripting' started by LucioMaximo, Dec 3, 2014.

  1. LucioMaximo

    LucioMaximo

    Joined:
    Dec 3, 2014
    Posts:
    10
    Hi,

    I am making a shop menu for a part of the game. I intended to make the shop menu out of different clickable buttons for different items. Each button is an image with a shop item and price on it. If the user wants to buy an upgrade, they click the picture, and it deducts that value from their cash.

    I have made the following image: http://i.imgur.com/VNf2fHJ.png which is to be used as the first button.

    The image is assigned via unity's inspecter onto the c# script PlayerController.cs

    public Texture shopMenuItem1;

    void OnGUI() {
    if (!shopMenuItem1) {
    Debug.LogError("Please assign a texture on the inspector");
    return;
    }
     
  2. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    The code you've posted only checks if something is assigned in the inspector.

    You need to use GUI.Button to actually display a button
     
  3. LucioMaximo

    LucioMaximo

    Joined:
    Dec 3, 2014
    Posts:
    10
unityunity