What would be the easiest way to move values from C# to JS? I.E. I want to utilize a Vector4 Array in javascript, that I built in C#.
For the record, I’m aware of <%item.value%>, I’m wondering if Unity provides any alternative solutions.
You probably want Application.ExternalCall or Application.ExternalEval, which tell the Javascript in the webplayer container page to run some Javascript in different ways.
See http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html
Would this only work for an application built into the webplayer then?
someJS.js:
function Start () {
print(GetComponent.<someCS>().someArray[0]);
}
someCS.cs:
using UnityEngine;
using System.Collections;
public class someCS: MonoBehaviour {
public Vector4[] someArray;
void Start () {
someArray = new Vector4[1];
someArray[0] = new Vector4( 0, 1, 2, 3 );
}
}
The only trick is that the cs must compile first - put it into plugins, or Standard Assets
That might be perfect, pre-comp is fine, how exactly does the print work? Wouldn’t that print the values to the display? I want to insert the values I’m pulling into a javascript function similar to a vector4.
Would something like:
function Start () {
Vector4(print(GetComponent.<someCS>().someArray[0]))
}
or
function Start () {
var VectorHolder = "print(GetComponent.<someCS>().someArray[0])";
Vector4(VectorHolder);
}
work for example?
no no no
print the same as Debug.Log(“anything”)
it just prints it to the console
You dont need to do anything, just
GetComponent.().someArray is the array in the c# component