Is there a way to reference a line in javascript from C#? For instance, in JavaScript, I have a variable called timer. And in C#, I have an input event that when pressed, I’d like it to reset the timer in JavaScript?
Atm, I’ve already attached the javascript to the same gameobject with the C# in the inspector. I’ve tried using the code example in the manual:
void Update()
{
ScriptName sn = gameObject.GetComponent<ScriptName>()
sn.DoSomething();
sn.someVariable=5;
}
It doesn’t work and I’m getting this error “Are you missing a using directive or an assembly reference?”
Nope I’ve tried that one as well. Same errors. As for reading the script reference, I’ve been reading this. I’ve tried other methods as well. Unfortunately, I got stuck so was wondering if I’m missing anything.
I know how to reference a variable from JavaScript to JavaScript but not sure how to do it from JavaScript to C#. Only if it’s possible though.
Could this be to do with the order scripts get compiled.
I may be totally wrong but I’m sure there is a section in the docs about JavaScript / C# mixed usage. I think maybe the script in question needs to be in a different directory within your project.
Like I said, I could have imagined this, but have a look.
I realised I’d better start doing some c# now because in the future it will be inevitable.
I was having the same GetComponent problem so Im now rewriting one of my JS files into c#.
Painful but Im sure some good will come from this in the future :lol: