Search Unity

Question I have a problem im very stupid new and i dont understand it

Discussion in 'Scripting' started by PUGONNER, May 10, 2021.

  1. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    okokokok so here is my code:


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {

    public float movespeed = 5f;

    public Rigidbody2D rb;

    public Vector2 MoveDirection

    void Update()
    {

    ProcessInputs();

    }



    void FixedUpdate()
    {

    move();

    }

    void ProcessInputs()
    {

    float moveX = Input.GetAxisRaw("Horizontal");
    float MoveY = Input.GetAxisRaw("Vertical");

    MoveDirection = new Vector2(moveX, MoveY); //
    }

    void move()
    {

    rb.velocity = new Vector2(MoveDirection.X * movespeed, MoveDirection.y
    * movespeed);

    }

    my problem is error cs1002 expected on line 12,18 also what does that number mean?

    12 is the line but what is 18, pls help me
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Since we're just sharing error codes, check out microsoft's page describing that one: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1002

    It should explain everything.

    12 is the line.
    18 is the column in the line.

    And you missed the most important part of your error message, the semicolon:
    ;
    which not coincidentally is the same thing your code is missing.
     
  3. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    Well now i think i have to make an entire other script, now it says error CS1061: "Vector2" does not contain a definition for X and no accessible method X accepting a first argument of type "vector2" could be found (are you missing a using directive or an assembly reference?)

    The last part i think is the problem but idk what is directive or an assembly reference
     
  4. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Your error seems to be at
    public Vector2 MoveDirection
    , your missing a
    ;
    . your answer is in the error message. As PraetorBlue said, 12 is the line and 18 is the column in the line. Make sure you read your error message and try figure it out your self.

    Whenever you post code snippets, Always use code tags, how to use them? Read this:
    https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  5. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Post your new script, So we can see what you did wrong and what you did right.
     
  6. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    It
    its the same but with a ; where it was supposed to be

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {

    public float movespeed = 5f;

    public Rigidbody2D rb;

    public Vector2 MoveDirection;

    void Update()
    {

    ProcessInputs();

    }



    void FixedUpdate()
    {

    move();

    }

    void ProcessInputs()
    {

    float moveX = Input.GetAxisRaw("Horizontal");
    float MoveY = Input.GetAxisRaw("Vertical");

    MoveDirection = new Vector2(moveX, MoveY); //
    }

    void move()
    {

    rb.velocity = new Vector2(MoveDirection.X * movespeed, MoveDirection.y
    * movespeed);

    }




    }
     
  7. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    I literally just mentioned earlier to use code tags, your error seems to be in your
    void move()
    function,
    MoveDirection.X
    vs
    MoveDirection.x
     
  8. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    Bruh, like i said sorry im stupid, in any case im starting so better get this errors out of the way and start typing ; when i need to
     
  9. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    ACTUALLY it aint not working,
    Vector 2 still does not contain a def. For X what change is that now there is no def. For Y either, i just want to know how to give vector 2 a def for x and y
     
  10. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    C# is a caps sensitive language. "X" and "x" are two different things. Vector2 does not contain a field called "X", but it does contain one called "x". Did you make sure you are using a lower case x and y?

    Post your modified script with code tags so we can see what is wrong. If you do not understand how to use code tags, follow this guide: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  11. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.  
    8.   public float movespeed = 5f;
    9.  
    10.   public Rigidbody2D rb;
    11.    
    12.   private Vector2 MoveDirection;
    13.  
    14.   void Update()
    15. {
    16.  
    17.   ProcessInputs();
    18.  
    19. }
    20.   void FixedUpdate()
    21. {
    22.  
    23.   move();
    24.  
    25. }
    26.  
    27. void ProcessInputs()
    28. {
    29.  
    30. float MoveX = Input.GetAxisRaw("Horizontal");
    31. float MoveY = Input.GetAxisRaw("Vertical");
    32.  
    33. MoveDirection = new Vector2(MoveX, MoveY); //
    34. }
    35.  
    36. void move()
    37. {
    38.  
    39. rb.velocity = new Vector2(MoveDirection.X * movespeed, MoveDirection.Y
    40. * movespeed);
    41.  
    42. }
    43.  
    44.  
    45.  
    46.  
    47. }
    48.  
    Like this?, also does it needs to be lower case i just made everything upper case
     
  12. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Like Johan_Liebert123 said:

    MoveDirection.X should be MoveDirection.x

    and

    MoveDirection.Y should be MoveDirection.y
     
    PUGONNER likes this.
  13. PUGONNER

    PUGONNER

    Joined:
    May 10, 2021
    Posts:
    7

    THANKS SO MUCH to everyone that helped me you dont belive how much i wanted to quit, it works now thanks so much
     
  14. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909