There is a line SendMessage('MyGameObject', 'MyFunction'); what should be in the receiving function?

Hi to all, make the game for web in unity. there is a line SendMessage('MyGameObject', 'MyFunction',3); which passes the value from HTML page in unity("Object","Function",the Value(can be empty)). The question that should be in this function?
June 14th 19 at 18:30
3 answers
June 14th 19 at 18:32
Solution
The arguments can be anything, depends on your needs. Drive in both directions json and you will be happy. The receiving function should be something like this : MyFunction(string arg)
Hi. Another question. I have a text variable Textname. How do I output the resulting value using the variable? - cale_OConner7 commented on June 14th 19 at 18:35
Withdraw to where? If in console then unity Debug Log(Textname). If in the browser console from the js console.log(Textname). Well, if you ask then ask in more detail, as your question is not clear what the result should be - tomas_Upt commented on June 14th 19 at 18:38
Pass in the object as text? - cale_OConner7 commented on June 14th 19 at 18:41
answers.unity3d.com/questions/825602/browser-to-un... - tomas_Upt commented on June 14th 19 at 18:44
Hi. You wrote something about the drive in both directions json. How to do it? - cale_OConner7 commented on June 14th 19 at 18:47
June 14th 19 at 18:34
Solution
Nothing special. It should be a public function called MyFunction in a script on the object name MyGameObject.
If you pass the parameter must be a parameter of the function. as far as I remember only accepts a string. Therefore, the parameter must be of type string
And how to bring the value of this parameter well, for example in the text? For this I have the script:
using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
using UnityEngine.SceneManagement; 
using System; 

public class SafingLoading : MonoBehaviour 
{ 
public Slider slider; 
public int Level; 
private int slidV; 
private float timer; 


public Text Textname; 
public Text Textlastname; 

// Use this for initialization 
void Start () { 

} 

// Update is called once per frame 
void Update() 
{ 
slider.value = slidV; 
timer += 6 * Time.deltaTime; 
if (timer >= 2) 
{ 
slidV += 7; 
timer = 0; 
} 
if (slider.value >= 100) 
{ 

#if UNITY_WEBGL 
Application.ExternalCall("inform"); //function Call inform, which in turn causes ('MyGameObject', 'Prin',3) 

#endif 

} 
} 


public void Prin(string arg) 
{ 
//The question of how to make something like a variable Textname was equal to the passed parameter?

} 

}
- cale_OConner7 commented on June 14th 19 at 18:37
//The question of how to make something like the variable was equal to

//parameter?
You mean what kind of variable ? args?
And so it will be equal to parameter b..showed better challenge ('MyGameObject', 'Prin',3)
this is the last option. do you have it string?
have you checked public void Prin(string arg) called in General? and what is args? - tomas_Upt commented on June 14th 19 at 18:40
I have in the script has a public variable Textname. I want the value of the Textname was equal to the value of args. Sorry I'm not good C#. The parameter is a number. - cale_OConner7 commented on June 14th 19 at 18:43
You do understand that where made..??
you are on the side js script/browser trigger ('MyGameObject', 'Prin',3) , only the parameter making LINE
in this string - substitute - everything your heart desires. want your Textname, want something else.
then in unity-script - work Prin method(string arg)
where args-is exactly what you passed in a string called from a js script.

I don't know how clearly you explain. or do I fail to understand (or to explain) what you do not understand..

in General, if there are such banal questions...can you some basics to read to find out, learn, and then to go deeper? - tomas_Upt commented on June 14th 19 at 18:46
Thank you very much. Yes, it seems worth it! - cale_OConner7 commented on June 14th 19 at 18:49
June 14th 19 at 18:36
Finally did. Thank you for the patience and for the help!
https://vk.com/app6193778_209422110

Find more questions by tags Development of gamesUnity Game Engine