How to pass variable js to c#

Sad
hello all

How to pass variable js to c#
i have js file name of Car and other file in C# name of progresbar.

so i want to pass variable js to c#

  1. pls give me structure of coding.
  2. if you have some link or example pls give me

Thanks in advance

pleae help me i m new in unity3d

thanks

If you want to access C# scripts from JS, then put C# in Plugin directory.

thanks

i already place c# in standard Assets

my C# code
print(GameObject.Find(“Car”).GetComponent(“Car”).energyLevel);

my js code
var energyLevel:float;

The print statement isn’t available in C#, so the code you’ve posted might need some work. However, you can access variables from a JS script in C# using the GetComponent function. A JS script defines a class with the same name as the script file (so a file called Player.js defines a class called Player). In the C# script, you use GetComponent on the GameObject with the JS script attached to get a reference to the script component. Once you have that, you just refer to its variables as members of the object:-

// JS file called Player.js
var hitPoints: int;
var indestructibleMode: boolean;
  ...


// C# code
GameObject playerObj;  // Get a reference to this somehow.
Player pl = playerObj.GetComponent<Player>();
pl.indestructibleMode = true;
int pointsLeft = pl.hitPoints;
  ...

hey,
When I did like this,its raising an error saying the javascript code cannot be found.

Same here :frowning:

on iOS, the communication is only 1 way, JS → C#, you can not talk the other way round

Ah cool! Good to know! Thank you for clearing this up!