Search Unity

Vector3

Discussion in 'Getting Started' started by melisagus92, Sep 16, 2019.

  1. melisagus92

    melisagus92

    Joined:
    Sep 16, 2019
    Posts:
    3


    i dont have Vectors in my visual studio. following the youtube video


    vector is suppose to be some sort of function but for me its a keyword and it dosent work. why?
     
  2. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
  3. melisagus92

    melisagus92

    Joined:
    Sep 16, 2019
    Posts:
    3
    i mean Vector 3 the first one

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Följspelare : MonoBehaviour
    4. {
    5.     public Transform Player;
    6.  
    7.     public vector3
    8.  
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         transform.position = Player.position;
    13.     }
    14. }
    15.  
    the error i get
    Assets\Scenes\F�ljspelare.cs(11,5): error CS1519: Invalid token 'void' in class, struct, or interface member declaration
     
  4. Neriad

    Neriad

    Joined:
    Feb 12, 2016
    Posts:
    125
    In the video, he shows what to write

    public Vector3 offset;
     
  5. melisagus92

    melisagus92

    Joined:
    Sep 16, 2019
    Posts:
    3
    Thank you it worked.
     
  6. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Just to make sure you understand what went wrong, there were actually 2 problems with your code example.
    1) Capital letters matter, so vector3 does not exist, but Vector3 does.
    2) You did not specify a name for that variable, nor did you end the line with a semicolon. That's why the error was confused about "void" - from its perspective you wrote "public vector3 void Update()", which makes no sense. Spaces and newlines are only there for you, they dont exist from the compilers point of view. So things need to be either enclosed in curley brackets (classes, methods, ..) or ended with a semicolon (declarations, most other things).

    While i'm at it, you may wanna follow common coding conventions:
    - Naming conventions mostly use camelCase, meaning you capitalize the letter of each new word in the string. For most things (variables and such), start with a lower case letter. So "Player" should be "player". Methods, Classes and Properties however should be defined in upper camel case, starting with a capital letter.
    - It is bad practice to use language specific letters like "ö" for anything other than in comments.
    - It is generally adviced to write code in english, since most of the methods you use are english anyways (consistency) and it helps others understanding your code better, which is especially important when you are going to post it online for help. Technically this includes comments, but that's rather a nice to have.
     
    Ryiah, Vryken and JoeStrout like this.