Search Unity

Incoming Notification Message?

Discussion in 'Immediate Mode GUI (IMGUI)' started by TB0Y298, Feb 11, 2013.

  1. TB0Y298

    TB0Y298

    Joined:
    Dec 25, 2012
    Posts:
    59
    Hi,
    I wanted to make a "basic" notification system for my game, and messed it a bit up. :mad:
    I can't still find a way out.
    For example i want to make something like this:
    http://www.gameprefabs.com/products/show/52

    DEMO:
    http://www.gameprefabs.com/products/preview/52

    I just want to know how to make a incoming message displaying at the right bottom of my screen.
    But how? Im not a good scripter in GUI things :confused:

    Please reply if you know a solution for it :(
     
  2. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    There is an excellent (and inspiring) plugin for Unity which is a GUI-messaging system and much more: ScoreFlash.

    You should definitely check it out! :)
     
  3. TB0Y298

    TB0Y298

    Joined:
    Dec 25, 2012
    Posts:
    59
    WOW, Wow, wow, I think thats to difficult for me to understand.
    I'd like to know how to make a "simple" script in Unity.
     
  4. Dextero

    Dextero

    Joined:
    Feb 2, 2013
    Posts:
    108
    A simple way to do this is by using a coroutine. The coroutine will show a GUI element for X amount of time and then hide it. If you want it to tween the movement/alpha etc, these are more complicated features you can research.

    E.g.

    Code (csharp):
    1.  
    2.  
    3. bool showNotification = false;
    4. string notificationToShow = "This is a notification";
    5.  
    6. void OnGUI(){
    7.         if(showNotification){
    8.                 //Shows a notification in the bottom right of the screen, with text notificationToShow
    9.                 GUI.Box(new Rect(Screen.width - 205, Screen.Height - 105, 200, 100), notificationToShow);
    10.         }
    11. }
    12.  
    13.  
    14. //Shows the notification for 2 seconds then hides it
    15. IEnumerator ShowNotification () {
    16.         showNotification = true;
    17.         yield return new WaitForSeconds(2.0f);
    18.         showNotification = false;
    19. }
    20.  
    21. //Usage
    22. void SomeMethod(){
    23.         if(doneSomething){
    24.                 notificaitonToShow = "You've done something";
    25.                 StartCouroutine(ShowNotification ());
    26.         }
    27. }
    28.  
    29.