**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("getDefault")) {
deviceLanguage = locale.Call("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("currentActivity")) {
cls_SpeechActivity.CallStatic("Init", obj_Activity);
}
}
}
public bool isInitialized() {
return cls_SpeechActivity.CallStatic("engineInitialized");
}
public void Speak(string Text) {
cls_SpeechActivity.CallStatic("Speak", Text);
}
public bool isSpeaking() {
return cls_SpeechActivity.CallStatic("isSpeaking");
}
public int SetPitch(float thepitch)
{
return cls_SpeechActivity.CallStatic("setPitch", thepitch);
}
public int SetSpeechRate(float therate)
{
return cls_SpeechActivity.CallStatic("setSpeechRate", therate);
}
public int SetLanguage(string Text) {
return cls_SpeechActivity.CallStatic("setLanguage", Text );
}
public string GetLanguage() {
return cls_SpeechActivity.CallStatic("getLanguage" );
}
public string getAllLanguages() {
return cls_SpeechActivity.CallStatic("getAllLanguages" );
}
public void Dispose() {
cls_SpeechActivity.Dispose();
}
**please help me, I need all of you who are expert in unity
thank you in advance!**
↧