Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by El Maxo · Jan 30, 2015 at 09:22 AM · c#javascriptc# to javascript

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;





Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image El Maxo · Jan 30, 2015 at 10:27 AM 0
Share

at the moment the character controller works perfect for what I need, so maybe just coding the ladderscript is js would be easyer?

avatar image Baste · Jan 30, 2015 at 02:22 PM 1
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there eval() for C#? 2 Answers

Trying to figure out how to translate these gravity script to Javascript 2 Answers

Sending the C# function parameter to JS function. 1 Answer

Multiple Cars not working 1 Answer

Lower player's health from separate script. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges