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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Error Rigidbody

Discussion in 'Scripting' started by Givago, Oct 22, 2015.

  1. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    Hi, I'm doing a tutorial and on tutorial it is the following code:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var velocidade: float;
    4.  
    5. var velocidadeAtual: float;
    6.  
    7. function Start () {
    8.  
    9.    Rigidbody myRigidbody = (Rigidbody).GetComponent(typeof(Rigidbody));
    10.  
    11. }
    12.  
    13. function Update () {
    14.  
    15.     velocidade = 0.5;
    16.    
    17.     velocidadeAtual = myRigidbody.velocity.magnitude;
    18.    
    19.     myRigidbody.velocity += transform.forward*velocidade*Input.GetAxis("Vertical");
    20.  
    21. }
    but it is giving error on my.
     
  2. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    So the first error I can see is that you use javascript, the second being that you didn't actually post what the error was.
     
  3. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    Sorry =P I am using java to a problem with that? (do not know).

    ERROR:
    Assets/MovimentacaoCarro.js(9,13): UCE0001: ';' expected. Insert a semicolon at the end.
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I dont know javascript, but is there suppose to be a period after (Rigidbody) cast in the start method?
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    The syntax is
    Code (csharp):
    1. var myRigidbody : Rigidbody;
    2. function Start() {
    3. myRigidbody = GetComponent.<Rigidbody>();
    4. }
    ....but to be fair, you should absolutely be learning C# instead, especially since that seems to be closer to your way of thinking already.
     
  6. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    still has the same error.
    Is that to wanting to do this tutorial and understand Rigidbody
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Can you post the entire script as it is now?
     
  8. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    Thank you, it worked now.
    I had a small mistake.