Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Java scripting to change component values

Discussion in 'Scripting' started by John10v10, Oct 17, 2013.

  1. John10v10

    John10v10

    Joined:
    Oct 17, 2013
    Posts:
    3
    Hi, would like to know how to use a JavaScript to change the component values on a game object in game :confused:. I'm trying to make it that if you press the left arrow key, it will set the hinge joint component's motor force to -500, and it will turn a rigid wheel to roll left; if you press the right arrow key, the motor force will change the motor force value to +500, and the whell will roll right.
     
    Last edited: Oct 17, 2013
  2. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    you would first make a variable with that name of component as variable type then call it
    var jointComponenet : HingeJoint;
    then you would drag the component in it and then just call what you want
    jointComponent.Axis = Vector3(0,1,0);

    that's one simple way of doing it other than that look at the manual just type component or get component and it's under gameobject too in the manual.
     
  3. John10v10

    John10v10

    Joined:
    Oct 17, 2013
    Posts:
    3
    Dude, thank you very much!!! I couldn't do exactly what you told me to do, but you brought me to the right path to sucess!!! I feel like a genius thanks to you. I knowledge in javascripting isn't even a week old yet and I made it this far. Thank you so much.:D:D:D:D:D