Here is a basic example of how to make a C# script contact a JavaScript:
First Create a C# Script call is test and a JavaScript call it test2, then create a plugins folder and put the JavaScript in the plugins folder.
Open the C# Script
void OnGUI() {
if (GUI.Button(new Rect(10, 170, 50, 30), "Click"))
Add this code under the Void Update.
Then add:
test T ;
under:
public class test2 : MonoBehaviour {
and this:
T=GetComponent ();
in the void start.
Then under:
if (GUI.Button(new Rect(10, 170, 50, 30), "Click"))
add:
T.count++;
Then go to your Java Script code and add:
var count : int = 0;
Under:
#pragma strict
Finally then add:
function OnGUI() {
if (GUI.Button(Rect(10,70,50,30),"Click ("+count+")"))
}
at then your code should work.
When you launch your game there will be 2 buttons on the screen, the top one will have a number on it and if you click the bottom one the number will go up by one and the C# script will contact the JavaScript.
↧