Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

"'UnityEngine.vector3' is a 'type' but is used as a 'variable'' error.

Discussion in 'Editor & General Support' started by Brian-Washechek, Feb 9, 2018.

  1. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    272
    I have little knowledge regarding ths error. I thought I was following this tutorial pretty decently, but at roughly 6 minutes I run into this error:
    2-9-2018.png
    I don't know how to deal with this error other than posting on this forum about it. I tried Google-ing it, but my search came back with no acceptable results. Thanks if you'll help me.
     
    Last edited: Feb 9, 2018
  2. RafaelF82

    RafaelF82

    Joined:
    Oct 28, 2013
    Posts:
    71
    Try this :

    rigidbody.velocity = new Vector3(moveHorizontal, 0.0f, moveVertical);

    and find a book about C#, with the language basics, one that teaches you what are variables, classes, etc.
     
  3. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    272
    When I change it to that I get an " 'UnityEngine.Component' does not contain a definition method 'velocity' acceptng a first arguement of type 'UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)" error on my "rigidbody.velocity" line.

    Am I missing a using directive or an assembly reference?
     
    Last edited: Feb 9, 2018
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    1,351
    How to use Rigidbody.velocity:
    https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html

    Something like this probably works:

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. private Rigidbody myRigidbody;
    6.  
    7. void Start ()
    8. {
    9.     myRigidbody = GetComponent<Rigidbody>();
    10. }
    11.  
    12. {
    13.     float moveHorizontal = Input.GetAxis("Horizontal");
    14.     float moveVertical = Input.GetAxis("Vertical");
    15.  
    16.     myRigidbody.velocity = new Vector3(moveHorizontal, 0.0f, moveVertical);
    17. }
    Also, post your code using code tags instead of images. It makes it easier for people to make changes to your code and show it to you rather than just throwing single command ideas at you.
     
  5. RafaelF82

    RafaelF82

    Joined:
    Oct 28, 2013
    Posts:
    71
    Sorry I forgot that using the rigidbody property of the gameobject no longer worked, use the code Joe posted above and it will work.
     
  6. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    272
    I tried Joe-Censored's code and now it's saying "Unexpected symbol 'Rigidbody', expecting 'class', 'delegate', 'enum', 'partial' or 'sruct'" for the line
    Code (csharp):
    1. private Rigidbody myRigidbody;
     
    Last edited: Feb 12, 2018
  7. RafaelF82

    RafaelF82

    Joined:
    Oct 28, 2013
    Posts:
    71
    He forgot the class declaration, here :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7. private Rigidbody myRigidbody;
    8. void Start ()
    9. {
    10.     myRigidbody = GetComponent<Rigidbody>();
    11. }
    12. {
    13.     float moveHorizontal = Input.GetAxis("Horizontal");
    14.     float moveVertical = Input.GetAxis("Vertical");
    15.     myRigidbody.velocity = new Vector3(moveHorizontal, 0.0f, moveVertical);
    16. }
    17. }