Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

OnGUI not being called

Discussion in 'Extensions & OnGUI' started by endanegered, May 23, 2018.

  1. endanegered

    endanegered

    Joined:
    Aug 18, 2017
    Posts:
    4
    Hello, I'm new and have just been learning Unity the past couple weeks.

    I have been trying to make a simple card game and made GUI buttons to debug/verify new functions. It was working previously and then I'm not sure where it got messed up and I can't get it to work anymore. It stopped working in when I added a draggable script and added the event system and removing those two elements does not have any effect.

    This script is attached to a GameObject in the hierarchy and I have messed around with the layers, coordinates, and have not gotten anything to work. I have also tried adding it to the canvas, event system, camera, and attaching the DeckModel object to it before hitting play. The "DebugDeck" does not show up on the console so I know its not a matter of finding the buttons in the space. I'm sure its probably something small I'm missing or possibly clicked on. Let me know if I need to add or clarify anything.

    Any help is appreciated! Thanks!


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DebugDeck : MonoBehaviour {
    6.     [SerializeField] private DeckModel deck;
    7.     bool hit = false;
    8.  
    9.     public void OnGUI()
    10.     {
    11.         float xPos = Screen.width / 2;
    12.         float yPos = Screen.height / 2;
    13.         Debug.Log("DebugDeck");
    14.  
    15.         if (GUI.Button(new Rect(xPos, yPos, 100, 28), "Press"))
    16.         {
    17.             if (!hit)
    18.             {
    19.                 deck.DisplayCards();
    20.                 deck.ShowFaces();
    21.                 hit = true;
    22.             }
    23.             else
    24.             {
    25.                 deck.HideFaces();
    26.                 hit = false;
    27.             }
    28.         }
    29.  
    30.         if (GUI.Button(new Rect(xPos, yPos + 1, 100, 28), "Shuffle"))
    31.         {
    32.             deck.Shuffle();
    33.             deck.RemoveDisplay();
    34.             deck.DisplayCards();
    35.         }
    36.  
    37.         if (GUI.Button(new Rect(xPos, yPos + 2, 100, 28), "Reorder"))
    38.         {
    39.             deck.RemoveDisplay();
    40.             deck.InOrder();
    41.             deck.DisplayCards();
    42.             deck.ShowFaces();
    43.         }
    44.  
    45.         if (GUI.Button(new Rect(xPos, yPos + 3, 100, 28), "Deal"))
    46.         {
    47.             deck.Deal();
    48.         }
    49.  
    50.     }
    51. }
     
    Last edited: May 24, 2018
  2. endanegered

    endanegered

    Joined:
    Aug 18, 2017
    Posts:
    4
    I just ended up just creating a UI and putting buttons on there... Still couldn't figure out what happened with the script.
     
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    308
    The only thing I can think of is that the script wasn't enabled.