- Home /
Changing Value in JavaScript from C#
Hello,
I currently trying to get a ladder script in my game to work but I am running into a issue. The basic way of how my ladder will work is that it turns off ( changes it to zero) the objects gravity on the "Character Motor" script and then adds a force.
or' could be found (are you missing a using directive or an assembly reference?)
To my understand I think im just calling the other componets wrong, but I may be wrong about that, code below:
Ladder Script (c#):
if (collision.gameObject.tag == "Ladder") {
insideTrigger = true;
GameObject theplayer = GameObject.FindGameObjectWithTag ("Player") ;
CharacterMotor playerscript = theplayer.GetComponent<CharacterMotor> ();
playerscript.gravity = 0;
CharcterMotor (js):
public var gravity : float = 10.0;
Answer by Baste · Jan 30, 2015 at 09:37 AM
So, the reason why this isn't working is because you can't just straight up use things from a script in one language in a script in another language. This has to do with script compilation order, read up on it here. The short version is that your js scripts has to be already compiled when your c# scripts are compiled, otherwise the c# scripts can't see them.
For your own sanity, stick to one language in the project. Otherwise you'll have a huge headache whenever you're trying to make the two work together. If you have some standard scripts or some scripts off the asset store that are js scripts, and you want to use c#, that's possible, but it'll be quite a bit of pain.
Finally, the built-in character controllers are horrible, horrible, horrible. They work for your first game project and very basic prototypes, but if you have something larger, just write your own.
at the moment the character controller works perfect for what I need, so maybe just coding the ladderscript is js would be easyer?
Probably, yes. But, a better option is to just grab a C# version of the CharacterControllers.
There are also some people who's been kind enough to port them to C#, check this github. If you know C# better than JS (Or want to learn C# ins$$anonymous$$d of JS (Which you should)), that'll probably be easier.