Hello Im using an asset and most of it is in c# and I have this line.
public float maxTorque = 150.0f;
I’m learning javascript and I want to be able to change the value of the above float in a javascript script using something like this so if speed 1 maxTorque float will equal 150 and speed 2 will equal 200
static var speed1 = true;
static var speed2 = false;
function Update()
{
if (Input.GetKeyDown (KeyCode.G)
{
speed1 = false;
speed2 = true;
}
}
CSharp and JS can’t see each other at compile time (different compilers are used for each language), but already compiled scripts can be seen by any language. If you place the C# script in Plugins or StandardAssets, and the JS script in another Assets folder (Assets/Scripts, for example), the C# script will be compiled in the “first wave”, thus the JS script will know it and compile ok. And in code:
var csharpcomponent:CSharpComp;
function Start(){
csharpcomponent = this.gameObject.GetComponent(CSharpComp);
}
But this is bad practice to have a project with both JS and C#. You should consider translating all scripts to one unique language. I hope that it will help you.