Accessing JavaScript variable from C# and vice versa.


Test01JS _a = GameObject.Find ("Test01").GetComponent<Test01JS>();
print (_a.test01JS);

It says: The type or namespace name "Test01JS" could not be found. etc.

C# code is compiled before JS code, so in general, while JS code can access C# classes, the opposite is not possible. However, you can affect the order of compilation by moving scripts into special folders which are compiled earlier. You could move your Test01JS script to a folder called "Plugins" then it works.


see this tutorial: Unity3D: JavaScript -> C# or C# -> JavaScript access | 41 Post

download the example and you’ll see that is very simple

Assets/_Scripts/JumpPoint001.cs(6,16): error CS0246: The type or namespace name `levelLoader’ could not be found. Are you missing a using directive or an assembly reference?

levelLoader is my js file in the Standard Assets folder. Am I doing it wrong?
using UnityEngine;
using System.Collections;

public class JumpPoint001 : MonoBehaviour {
	port function.
	public levelLoader loadCheck;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
	void OnTriggerEnter(Collider other){
		loadCheck = this.GetComponent<levelLoader>();

Save GameObject States in a file you want to get in cs or js
Just import this file Js or C# you want