Hello to all. I need a little help to make a call of a C# through a js script in Unity3d. The script I’d like to call is named “IsometricBheaviour.cs” and it is placed in Asset/Plugins folder.
This is the coding of the “IsometricBheaviour.cs” script:
using UnityEngine;
using System.Collections;
public class IsometricBheaviour : MonoBehaviour {
private static bool mIsRotated = false;
private static bool mMustRotate = false;
private GameObject whatever;
// Use this for initialization
void Start ()
{
whatever = GameObject.Find ("MarkerObject");
}
// Update is called once per frame
void Update ()
{
// Update is called once per frame
}
void Isometric ()
{
if (mMustRotate !mIsRotated)
{
//Rotate all models 45 degrees around X
if (whatever != null) {
GameObject modelUnderChipsTrackable = whatever.transform.GetChild(0).gameObject;
modelUnderChipsTrackable.transform.RotateAround(new Vector3(1,0,0), Mathf.PI/3);
}
mIsRotated = true;
mMustRotate = false;
{
if (!mIsRotated)
{
mMustRotate = true;
}
}
}
}
}
The javascript that I want to use to call the “IsometricBheaviour.cs” script is basically a GUI controller script, with some buttons.
Here is the coding for calling the C# script:
#pragma strict
var native_width : float = 480;
var native_height : float = 320;
var ctrlImage : Texture2D;
var txtImage : Texture2D;
var btnTexture1 : Texture;
var btnTexture2 : ........... ;
var btnTexture3 : ........... ;
function Start() {
}
function Update() {
}
function OnGUI ()
{
//set up scaling
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
//now create your GUI normally, as if you were in your native resolution
//The GUI.matrix will scale everything automatically.
GUI.Box( Rect(10, 100, 420, 120) ,ctrlImage, "");
if (!btnTexture1)
{
Debug.LogError("Please assign a texture on the inspector");
return;
}
if(GUI.Button(Rect(40, 134 50, 30), btnTexture1));
var runScript1 : GameObject[] = GameObject.FindGameObjectsWithTag("markerObject");
for(var doIsometric : GameObject in runScript1)
{
var script1 : IsometricBheaviour = doIsometric.GetComponent(IsometricBheaviour);
if(script1)
{
IsometricBheaviour.doIsometric();
}
}
I cannot make it compile. I get the following error:
" Error BCE0018: The name ‘IsometricBheaviour’ does not denote a valid type (‘not found’). Did you mean ‘System.Net.Sockets.IOControlCode’? (BCE001 (Assembly-UnityScript-firstpass)"
Can someone help me, make this javascript work? I am new to Unity and programming and I got stuck on this big time now.
I have placed the C# in plugins folder as mentioned here http://answers.unity3d.com/questions/12248/i-need-to-call-a-c-function-from-javascript.html
and here https://docs.unity3d.com/Documentation/Manual/ScriptCompileOrderFolders.html
Still I get no compilation. Thank you all for your time, reading this post. Any advice, is very much welcomed.