I guess the keyword Javascript isn’t right. But don’t know where to check the correct syntax. Could someone help me, and also tell me where is the place to search this type of question? Thanks!
try that, but doesn’t work.
SendMessage works. But can I pass more than one variable in SendMessage? And I still want to know if C# call javascript is possible. Thanks for your help!
function Update ()
{
}
public function testFunc(a:String)
{
Debug.Log(a);
}
C#
using UnityEngine;
using System.Collections;
public class caller : MonoBehaviour {
private callee goScript;
// Use this for initialization
void Start ()
{
goScript = (callee) gameObject.GetComponent("testFunc");
}
// Update is called once per frame
void Update ()
{
}
}
the error message said:
Assets/caller.cs(5,17): error CS0246: The type or namespace name `callee’ could not be found. Are you missing a using directive or an assembly reference?
Sometimes it doesn’t recognize the JavaScript type unless it’s put in a special folder. I forget the specifics, but you’re pretty much stuck converting one or the other to the other language if you want easy communication.
the javascript needs to put to a directory like “Standard Assets” or something like GargerathSunman Eric suggested to be compiled first.
there are some minor bugs that I fixed.
C#
using UnityEngine;
using System.Collections;
public class caller : MonoBehaviour {
private callee goScript;
// Use this for initialization
void Start ()
{
goScript = (callee) gameObject.GetComponent("callee");
}
// Update is called once per frame
void Update ()
{
goScript.testFunc("1234");
}
}
callee.js (in “Standard Assets” directory)
function Update ()
{
}
public function testFunc(a:String)
{
Debug.Log(a);
}
then callee.js isn’t in the right place (please follow, read and understand the page linked above) or you have not assigned it to any game object thats active in the current scene where you look for it.