Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Clarenceonline · Sep 03, 2013 at 07:23 AM · c#androidonguiunityandroidgui layout

[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!

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Clarenceonline · Sep 03, 2013 at 10:21 AM 0
Share

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?

avatar image Clarenceonline · Sep 03, 2013 at 10:58 AM 0
Share

Please I need a your HELP or any response

avatar image oferei · Sep 03, 2013 at 01:30 PM 0
Share

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?

avatar image Clarenceonline · Sep 03, 2013 at 01:49 PM 0
Share

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.

avatar image oferei · Sep 03, 2013 at 02:55 PM 0
Share
 #if UNITY_ANDROID
     public AndroidJavaClass cls_SpeechActivity = new AndroidJavaClass("com.unity3d.plugin.AndroidTTSActivity");
 #endif

or perhaps the entire TTSBridge class.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Support the MONO AOT Compilation on Android 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges