Vector3

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?

Do you mean Vector3

or
Vector?

i mean Vector 3 the first one

using UnityEngine;

public class FĂśljspelare : MonoBehaviour
{
    public Transform Player;
  
    public vector3

    // Update is called once per frame
    void Update()
    {
        transform.position = Player.position;
    }
}

the error i get
Assets\Scenes\F�ljspelare.cs(11,5): error CS1519: Invalid token ‘void’ in class, struct, or interface member declaration

In the video, he shows what to write

public Vector3 offset;

Thank you it worked.

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.
3 Likes