I’m having problems in sending a message from a C# script to a JS script using SendMessage: does anyone know the proper syntax in C# ? Is there anywhere a sample script ?
in the script reference which is the first place you should be looking before posting :
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void ApplyDamage(float damage) {
print(damage);
}
void Awake() {
gameObject.SendMessage("ApplyDamage", 5.0F);
}
}
Well, that works till I stay in C#; if in the same GameObject I have a JS script
function ApplyDamage(theDamage ){
Debug.Log("HEY, YOU'RE IN JS ! " + theDamage);
}
then I get an exception (the first line is output from the C# script that works correctly):
DAMAGE FOUND (CS) 5
(Filename: /Applications/buildAgent/work/71ca6fec1b41cc30/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2528)
ExecutionEngineException: Attempting to JIT compile method ‘(wrapper dynamic-method) Boo.Lang.Runtime.RuntimeServices:RuntimeServices$op_Addition$System.String$System.Single (object,object[ ])’ while running with --aot-only.
at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in :0
at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in :0
at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in :0
at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in :0
at Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter.CreateMethodDispatcher () [0x00000] in :0
at Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter.Emit () [0x00000] in :0
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.EmitMethodDispatcher (Boo.Lang.Runtime.CandidateMethod found, System.Type[ ] argumentTypes) [0x00000] in :0
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[ ] args) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[ ] args) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices+c__AnonStorey13.<>m__7 () [0x00000] in :0
at Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, System.Object[ ] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[ ] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[ ] args) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.InvokeRuntimeServicesOperator (System.String operatorName, System.Object[ ] args) [0x00000] in :0
at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in :0
at storeKItTestGUI.ApplyDamage (System.Object theDamage) [0x00000] in :0
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.GameObject:SendMessage(String, Object)
StoreKitGUIManager:OnGUI()
(Filename: Line: -1)
It works on the desktop, but when compiled on iOS then I get this error; the matter is sending a message from a C# script to a JS script on iOS, which, according to the documentation, should be doable…
not sure about this because i never mix C# with UnityScript but try putting your UnityScript in the editor folder.
also please don’t double post the same issue since someone is replying in the other post : http://forum.unity3d.com/threads/91388-Exchange-variables-from-C-to-JS