x


problem with Unity.SendMessage !!!

Hi I wonder why it failed, I'm simply calling the player through a js function, but not working, there are requirements or anything special to prevent this from happening. Someone told me it was because I was trying to call an object that was already the son of a son of a son, and put it in the root of the inheritance, but does not work, js function works even before making the SendMessage, please help thanks .

JAVASCRIPT //

// get unity

 function getUniytPlayer()
 {
    var unity = unityObject.getObjectById("unityPlayer");
    return unity;
 }
 
 //send msg to the browser
 function test(str)
 {
    alert(str);
 }

 // data from flash
 function sendSkillsInfo(maxSkills,skillsSlots)
 {
 
 var slots = new Array();
 var slotsData = String(skillsSlots); 
 slots = slotsData.split('-');
 alert(maxSkills + " : " + skillsSlots); // 1 : image.jpg
  
     the script does not work here 
 getUniytPlayer().SendMessage("GameManager","assignskills");
 alert("Work it");
 }



// C# using UnityEngine; using System.Collections;

public class SkillsManager : MonoBehaviour {

 // Use this for initialization
 
 
 
 
 public void assignskills()
 {
     Debug.Log("*********");
     Application.ExternalCall("test","Unity !!!!");
 }
 
 

}

more ▼

asked Sep 06, 2011 at 04:28 PM

juliancruz87 gravatar image

juliancruz87
82 123 98 100

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I think this line:

 getUniytPlayer().SendMessage("GameManager","assignskills");

should be:

 getUniytPlayer().SendMessage("assignskills");

I'm not positive, just going off the documentation here.

more ▼

answered Sep 06, 2011 at 04:45 PM

Sigil gravatar image

Sigil
151 1 2 4

You are looking off of the wrong documentation. That is for GameObject.SendMessage and not Unity Player's SendMessage function. They are similar, but not the same. What you are looking for is here:

http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html

Unity Player's SendMessage needs both parameters, the first is the name of the GameObject, the second is the function name. It also has an optional 3rd paramater for passing a string to the receiving function. Essentially what it is doing when you call Unity.SendMessage("gameobject","function") is it does an internal GameObject.Find("gameobject").SendMessage("function");

Sep 06, 2011 at 05:03 PM equalsequals

Ah ok, so we can assume that he has a GameObject in his scene somewhere named GameManager, with the component SkillsManager on it. Got it.

Sep 06, 2011 at 05:08 PM Sigil

Correct. To iterate, say he has 2 components applied to this GameObject that both have a function "assignskills", calling the above function will result in both those components calling their "assignskills" function.

Sep 06, 2011 at 05:48 PM equalsequals

Thanks, other question, can I pass to a string Array? how can I?

Sep 06, 2011 at 07:09 PM juliancruz87

No, you can not pass an array of strings, only a single string.

Sep 06, 2011 at 07:45 PM equalsequals
(comments are locked)
10|3000 characters needed characters left

Unity has a problem with Unity.SendMessage seeing C#, if you were to convert your C# to a Unity JS class it would probably work.

Not sure why, it is possible that it may be something in the compilation order. In any case, any time you expect to receive Browser JS calls to Unity, the receiving class should be a JS class and not C#.

Cheers.

==

more ▼

answered Sep 06, 2011 at 04:57 PM

equalsequals gravatar image

equalsequals
5.2k 32 46 106

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x288
x3

asked: Sep 06, 2011 at 04:28 PM

Seen: 4866 times

Last Updated: Sep 06, 2011 at 07:46 PM