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

Unexpected smybol 'Vector3'

Discussion in 'Scripting' started by Skare, Feb 23, 2015.

  1. Skare

    Skare

    Joined:
    Feb 23, 2015
    Posts:
    4
    Hey Guys,
    I've got a problem at the Scripting in Unity3d

    ps: Im new at unity

    i hope somebody can help me :)
     

    Attached Files:

  2. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    Missing semi colon on the line before.
     
  3. Skare

    Skare

    Joined:
    Feb 23, 2015
    Posts:
    4
    no it says: An argurment is missing
     
  4. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Also there is an extra comma at the end of the line ,
     
  5. Skare

    Skare

    Joined:
    Feb 23, 2015
    Posts:
    4
    sorry guys but there's another error :
    Assets/Scripts/PlayerScript.cs(13,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)'
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Both responses you received previously are correct, so make sure you fix those errors.

    Read the API Guide for AddForce. The way you've tried calling it is by using it as a static method of the Rigidbody class. AddForce is actually an instance method, so you would call it on the RigidBody you want to add force to. If that rigidBody is parented to the object your current script is attached to, you can access that object using the word 'rigidBody'. So in your example:

    Code (CSharp):
    1. rigidBody.AddForce(movement);
    Notice the difference in capitalization which determines whether you're working with an instance or the class.
     
  7. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Rigidbody is the class while rigidbody is the instance. You want the instance.
     
  8. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    GameObject does not have an AddForce function. It is found on the Rigidbody component.
     
  9. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    You're right. I realized it just as I hit reply. Edited for the fix.
     
  10. Skare

    Skare

    Joined:
    Feb 23, 2015
    Posts:
    4
    thanks guys!

    when i start the game, it works.
    But: my character flies out of the ground
    error: The referenced script on this Behaviour is missing!

    what should i do now?
    plz help me, thanks
     
  11. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Typically, you should spend a bit of time trying to figure something out yourself before asking for help. Otherwise, why even bother creating the game yourself?

    The error you're describing probably means a script that was previously assigned to an object was moved, renamed, or deleted. Did you go moving files around or something?