Search Unity

[HELP] GUI not showing in camera

Discussion in 'Immediate Mode GUI (IMGUI)' started by Clarenceonline, Sep 2, 2013.

  1. Clarenceonline

    Clarenceonline

    Joined:
    Jul 1, 2013
    Posts:
    17
    good day,
    im trying to create a gui with the following code but when i dragged it to the camera it doesn't show.
    please help me, thanks in advance
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. using System;
    5.  
    6. using System.Collections;
    7.  
    8.  
    9.  
    10. public class Example : MonoBehaviour {
    11.  
    12.  
    13.  
    14.    private string [] LocalizedStrings;
    15.  
    16.  
    17.  
    18.    private static TTSBridge ttsengine;
    19.  
    20.  
    21.  
    22.    public Font unicodearial;
    23.  
    24.  
    25.  
    26.    string thetext = "Awesome dude! Input a phrase to speech.\n You can use enter to make a new line.\nTry something!";
    27.  
    28.    int retval;
    29.  
    30.    string deviceLanguage ="";
    31.  
    32.    string TTSLanguage ="";
    33.  
    34.    //string TTSLanguages="";
    35.  
    36.  
    37.  
    38.    float thepitch = 1.0f;
    39.  
    40.    float oldpitch = 1.0f;
    41.  
    42.    float therate = 1.0f;
    43.  
    44.    float oldrate = 1.0f;
    45.  
    46.  
    47.  
    48.  
    49.  
    50. #if UNITY_ANDROID
    51.  
    52.    void Start ()
    53.  
    54.    {
    55.  
    56.  
    57.  
    58.             AndroidJNI.AttachCurrentThread();
    59.  
    60.  
    61.  
    62.             // Retrieve device current language
    63.  
    64.             using (AndroidJavaClass cls = new AndroidJavaClass("java.util.Locale")) {
    65.  
    66.             using (AndroidJavaObject locale = cls.CallStatic<AndroidJavaObject>("getDefault")) {
    67.  
    68.             deviceLanguage = locale.Call<string>("getDisplayLanguage");
    69.  
    70.          }
    71.  
    72.       }
    73.  
    74.       // Startup vibration Java object
    75.  
    76.       ttsengine = new TTSBridge();
    77.  
    78.       ttsengine.Init();
    79.  
    80.  
    81.  
    82.    }
    83.  
    84. #endif
    85.  
    86.  
    87.  
    88.    void OnGUI()
    89.  
    90.    {
    91.  
    92.  
    93.  
    94.    GUI.color = Color.white;
    95.  
    96.    GUI.skin.font = unicodearial;
    97.  
    98.    GUILayout.BeginArea(new Rect(20, 10, Screen.width-40, Screen.height-80));
    99.  
    100.    GUILayout.Label("Android Native TTS engine plugin example demo");
    101.  
    102.    GUILayout.Space(10.0f);
    103.  
    104.    GUILayout.Label("device language:"+deviceLanguage);
    105.  
    106.    GUILayout.Space(10.0f);
    107.  
    108.    GUILayout.Label("TTS engine language:"+TTSLanguage);
    109.  
    110.  
    111.  
    112.    if(ttsengine.isInitialized())
    113.  
    114.       TTSLanguage = ttsengine.GetLanguage();
    115.  
    116.  
    117.  
    118.    if(GUILayout.Button("Switch to english", GUILayout.Height(40)))
    119.  
    120.    {
    121.  
    122.    #if UNITY_ANDROID
    123.  
    124.       retval = ttsengine.SetLanguage("inglese");      
    125.  
    126.       Debug.Log( "setLanguage(US) returned: "+retval);
    127.  
    128.    #endif
    129.  
    130.    }
    131.  
    132.  
    133.  
    134.    GUILayout.Space(10.0f);
    135.  
    136.    if(GUILayout.Button("Switch to "+deviceLanguage+"(default)", GUILayout.Height(40)))
    137.  
    138.    {
    139.  
    140.       #if UNITY_ANDROID
    141.  
    142.       retval=ttsengine.SetLanguage("italiano");
    143.  
    144.       Debug.Log( "setLanguage(ITA) returned: "+retval);
    145.  
    146.       #endif
    147.  
    148.    }
    149.  
    150.  
    151.  
    152.    GUILayout.Space(40.0f);
    153.  
    154.  
    155.  
    156.    GUILayout.Label("Set pitch: "+thepitch);
    157.  
    158.    thepitch = GUILayout.HorizontalSlider(thepitch,0.1f,2.0f, GUILayout.Height(50));
    159.  
    160.    if (thepitch!=oldpitch)
    161.  
    162.    {
    163.  
    164.       oldpitch=thepitch;
    165.  
    166.    #if UNITY_ANDROID
    167.  
    168.       ttsengine.SetPitch(thepitch);
    169.  
    170.    #endif
    171.  
    172.    }
    173.  
    174.  
    175.  
    176.  
    177.  
    178.    GUILayout.Space(30.0f);
    179.  
    180.    GUILayout.Label("Set speed: "+therate);
    181.  
    182.    therate = GUILayout.HorizontalSlider(therate,0.5f,2.0f, GUILayout.Height(50));
    183.  
    184.    
    185.  
    186.    if (therate!=oldrate)
    187.  
    188.    {
    189.  
    190.       oldrate=therate;
    191.  
    192.       #if UNITY_ANDROID
    193.  
    194.       retval=ttsengine.SetSpeechRate(therate);
    195.  
    196.       #endif
    197.  
    198.    }
    199.  
    200.  
    201.  
    202.    GUILayout.Space(20.0f);
    203.  
    204.  
    205.  
    206.    thetext = GUILayout.TextArea( thetext, 200 );
    207.  
    208.    GUILayout.Space(20.0f);
    209.  
    210.    if(GUILayout.Button("TALK", GUILayout.Height(80)))
    211.  
    212.    {
    213.  
    214.          // talk
    215.  
    216. #if UNITY_ANDROID
    217.  
    218.          ttsengine.Speak(thetext.ToLower());
    219.  
    220. #endif
    221.  
    222.       }
    223.  
    224.       GUILayout.Space(30.0f);
    225.  
    226.       GUILayout.EndArea();
    227.  
    228.       GUI.Label(new Rect(0,Screen.height-40,Screen.width,40),"Litobyte Softworks - Native TTS engine plugin v 1.1.0");
    229.  
    230.  
    231.  
    232.    }
    233.  
    234.  
    235.  
    236.    void OnApplicationQuit()
    237.  
    238.    {
    239.  
    240.       ttsengine.Dispose();
    241.  
    242.    }
    243.  
    244.  
    245.  
    246. }
     
  2. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    Hi,

    what do you mean by "dragging it to the camera"?

    If you are trying to render UnityGUI through camera, well that's impossible. The reason is that UnityGUI renders everything over all the other stuff in the scene (renders last in the screen 2D plane).

    The fact that the OnGUI method is implemented in the script attached to a 3D game object could be a bit misleading.