- Home /
Passing parameter from native android
Hi , I want to pass parameters between my Android native code and my Unity project. I can pass variable from my Unity project to my native android code but I haven't found a way to pass parameters from my native code to my Unity project.
I'll appreciate if someone can help me with this.
thanks very much
Yes, I don't know exactly which post , but it was a post on unity answers , search for it and you should find it ,if not let me know
@smtabatabaie okay will search for the post. if i didn't find i will get back to you. thanks for your reply
I posted a bunch of Android plugin links in this page. One of them has the information you are looking for.
@smtabatabaie couldn't find any. if you could give me a example or pseudocode it will be really helpful
Answer by Mohsenasm · Aug 05, 2015 at 12:48 PM
you can use this method to call a C# (or JS) method in unity with a string parameter:
UnityPlayer.UnitySendMessage(your_gameObject_name, your_method_Name, "message");
if you want to pass more parameter you can call your_method to get more variable:
// in java
UnityPlayer.UnitySendMessage(your_gameObject_name, your_method_Name, "Ready");
// ...
public static int int_param;
public static int getnum(){
return int_param;
}
// in C#
public void your_method_Name(string message){
if (message == "Ready"){
int param = your_java_class.CallStatic<int>("getnum");
// ...
}
}
@$$anonymous$$ohsenasm , @smtabatabaie , @meat5000 thanks a lot,it worked.
I cann't find this function your are talking about, is there any other way to pass parameters to Unity?