- Home /
[HELP] C# GUI, not showing up in camera
Hello everyone, im new to unity and C# please help. The GUI layout, label and buttons are not showing up when i drag them to camera or deploy it on an android phone. The script is written in C# and I want to develop an android application that use this 2 scripts The code is below. Anyone, Please help me in this problem. I will appreciate any HELP. please try give a solution to this, i need your expertise please.
using UnityEngine;
using System;
using System.Collections;
public class Example : MonoBehaviour {
private string [] LocalizedStrings;
private static TTSBridge ttsengine;
public Font unicodearial;
string thetext = "Awesome dude! Input a phrase to speech.\n You can use enter to make a new line.\nTry something!";
int retval;
string deviceLanguage ="";
string TTSLanguage ="";
//string TTSLanguages="";
float thepitch = 1.0f;
float oldpitch = 1.0f;
float therate = 1.0f;
float oldrate = 1.0f;
#if UNITY_ANDROID
void Start () {
AndroidJNI.AttachCurrentThread();
// Retrieve device current language
using (AndroidJavaClass cls = new AndroidJavaClass("java.util.Locale")) {
using (AndroidJavaObject locale = cls.CallStatic<AndroidJavaObject>("getDefault")) {
deviceLanguage = locale.Call<string>("getDisplayLanguage");
}
}
// Startup vibration Java object
ttsengine = new TTSBridge();
ttsengine.Init();
}
#endif
void OnGUI() {
GUI.color = Color.white;
GUI.skin.font = unicodearial;
GUILayout.BeginArea(new Rect(20, 10, Screen.width-40, Screen.height-80));
GUILayout.Label("Android Native TTS engine plugin example demo");
GUILayout.Space(10.0f);
GUILayout.Label("device language:"+deviceLanguage);
GUILayout.Space(10.0f);
GUILayout.Label("TTS engine language:"+TTSLanguage);
if(ttsengine.isInitialized())
TTSLanguage = ttsengine.GetLanguage();
if(GUILayout.Button("Switch to english", GUILayout.Height(40)))
{
#if UNITY_ANDROID
retval = ttsengine.SetLanguage("inglese");
Debug.Log( "setLanguage(US) returned: "+retval);
#endif
}
GUILayout.Space(10.0f);
if(GUILayout.Button("Switch to "+deviceLanguage+"(default)", GUILayout.Height(40)))
{
#if UNITY_ANDROID
retval=ttsengine.SetLanguage("italiano");
Debug.Log( "setLanguage(ITA) returned: "+retval);
#endif
}
GUILayout.Space(40.0f);
GUILayout.Label("Set pitch: "+thepitch);
thepitch = GUILayout.HorizontalSlider(thepitch,0.1f,2.0f, GUILayout.Height(50));
if (thepitch!=oldpitch)
{
oldpitch=thepitch;
#if UNITY_ANDROID
ttsengine.SetPitch(thepitch);
#endif
}
GUILayout.Space(30.0f);
GUILayout.Label("Set speed: "+therate);
therate = GUILayout.HorizontalSlider(therate,0.5f,2.0f, GUILayout.Height(50));
if (therate!=oldrate)
{
oldrate=therate;
#if UNITY_ANDROID
retval=ttsengine.SetSpeechRate(therate);
#endif
}
GUILayout.Space(20.0f);
thetext = GUILayout.TextArea( thetext, 200 );
GUILayout.Space(20.0f);
if(GUILayout.Button("TALK", GUILayout.Height(80)))
{
// talk
#if UNITY_ANDROID
ttsengine.Speak(thetext.ToLower());
#endif
}
GUILayout.Space(30.0f);
GUILayout.EndArea();
GUI.Label(new Rect(0,Screen.height-40,Screen.width,40),"Litobyte Softworks - Native TTS engine plugin v 1.1.0");
}
void OnApplicationQuit()
{
#if UNITY_ANDROID
ttsengine.Dispose();
#endif
}
}
this is the TTSBRIDGE script the first script(Example.cs) is refering to
using UnityEngine; using System; using System.Collections;
public class TTSBridge : IDisposable {
private AndroidJavaClass cls_SpeechActivity = new AndroidJavaClass("com.unity3d.Plugin.AndroidTTSActivity");
public void Init() {
using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
cls_SpeechActivity.CallStatic("Init", obj_Activity);
}
}
}
public bool isInitialized() {
return cls_SpeechActivity.CallStatic<bool>("engineInitialized");
}
public void Speak(string Text) {
cls_SpeechActivity.CallStatic("Speak", Text);
}
public bool isSpeaking() {
return cls_SpeechActivity.CallStatic<bool>("isSpeaking");
}
public int SetPitch(float thepitch)
{
return cls_SpeechActivity.CallStatic<int>("setPitch", thepitch);
}
public int SetSpeechRate(float therate)
{
return cls_SpeechActivity.CallStatic<int>("setSpeechRate", therate);
}
public int SetLanguage(string Text) {
return cls_SpeechActivity.CallStatic<int>("setLanguage", Text );
}
public string GetLanguage() {
return cls_SpeechActivity.CallStatic<string>("getLanguage" );
}
public string getAllLanguages() {
return cls_SpeechActivity.CallStatic<string>("getAllLanguages" );
}
public void Dispose() {
cls_SpeechActivity.Dispose();
}
please help me, I need all of you who are expert in unity thank you in advance!
Anyone please help me. I got these error from these code
public AndroidJavaClass cls_SpeechActivity = new AndroidJavaClass("com.unity3d.plugin.AndroidTTSActivity");
ERROR Assets/Plugins/TTSBridge.cs(9,16): error CS0246: The type or namespace name `AndroidJavaClass' could not be found. Are you missing a using directive or an assembly reference?
how do i properly initialize the location of AndroidTTSActivity?
Relax, mate! have a beer.
About the AndroidJavaClass error, it sounds like you're not building for Android. wrap that code with "#if UNITY_ANDROID" to disable it for non-Android platforms.
About the GUI, I'm not sure what the problem is. Does you camera have a GUILayer component on it?
sir Oferei,
thank you for visiting my thread
regarding to the GUILayer, yes i have included the GUILayer component.
the one with the wrap that code you're saying I cannot understand it sir, could you please elaborate or give me an example using my code? I'm sorry for sharing my problem to you.
But please help me.
#if UNITY_ANDROID
public AndroidJavaClass cls_SpeechActivity = new AndroidJavaClass("com.unity3d.plugin.AndroidTTSActivity");
#endif
or perhaps the entire TTSBridge class.
Your answer
Follow this Question
Related Questions
Unity Ads is working in editor but not on android device 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Receipt JSON Split 0 Answers