- Home /
 
               Question by 
               Marcus Vinicius · Mar 27, 2015 at 05:23 PM · 
                javascriptwebgl  
              
 
              String coming as null from Unity to HTML WebGL
I'm making a communication test of Unity to HTML.
I created a button on Unity which when clicked, is to pass a string to the button that was created in HTML.
But the string comes to null.
This is the code Unity
 public class Teste : MonoBehaviour 
 {
     public UILabel label;
     public string testeString;
     
     //Funcçoes para mandar uma mensagem da unity para a web
     public void sendMensageFromUnity()
     {
         testeString = label.text;
         Application.ExternalCall("getFromUnity", testeString);
     }
 
 
     //Metodos para receber uma mensagem da web 
     public void getMensageFromWeb(string teste)
     {
         label.text = teste;
     }
 }
This is the code HMTL JavaScript
 script type="text/javascript" language="javascript">
     var u = new UnityObject2();
     var t = document.getElementById("btn1");//Variavel que associa o id do button.
 
     //Função que recebe uma mensagem da Unity e da uma mensagem de alerta.
     function getFromUnity( arg)
     {
       alert( arg );
       //document.getElementById("btn1").innerHTML = arg;
     }
 
     //Chegagem quando o botão é clicado.
     $(document).ready(function(){
       $("#btn1").click(function(){
           u.initPlugin(jQuery(t), "unityObjectUrl.unity3d");
           SaySomethingToUnity();
     });
 
     //Função que manda uma mensagem para unity.
     function SaySomethingToUnity()
     {
       u.getUnity().SendMessage("Button", "getMensageFromWeb", "Hello");
     }});
 
 </script>
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                