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

Need help with my first code!

Discussion in 'Getting Started' started by DragondMa, Jul 16, 2021.

?

Where is my mistake?

  1. Your Mistake is...

    0 vote(s)
    0.0%
  2. You can do this...

    1 vote(s)
    100.0%
  1. DragondMa

    DragondMa

    Joined:
    Jul 16, 2021
    Posts:
    3
    Hi,
    i'm just getting started with Unity, so i follewed a tutorial, but the code has some erros and i can't find the mistake.

    1 using System.Collections;
    2 using System.Collections.Generic;
    3 using UnityEngine;
    4
    5 public class Movement : MonoBehaviour
    6 {
    7 public float speed;
    8
    9 private Rigidbody2d rb;// Start is called before the first frame update
    10 private Vectore2 moveVelocity;
    11
    12 void Start()
    13 {
    14 rb = GetComponent<Rigidbody2d>();
    15 }
    16
    17 // Update is called once per frame
    18 void Update()
    19 {
    20 Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal") Input.GetAxis("Vertikal"));
    21 moveVelocity = moveInput.normalized * speed;
    22 }
    23
    24 void FixedUpdate()
    25 {
    26 rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
    27 }
    28}

    The errors is:
    Assets\Movement.cs(20,69): error CS1003: Syntax error, ',' expected

    I hope one of you can help me with it.
    Thanks.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    Welcome to the forums! Yes, we can help.
    1. When pasting code, use the "Code:" button in the editing toolbar.
    2. Don't append a poll to your message. I know it kinda looks like you have to, but you don't.
    3. The error message specifies Movement.cs(20,69). That tells you the file name and the location where the compiler got confused: 20 is the line number, 69 is the column. You should usually ignore the column, but pay attention to the line number.
    4. In this case that directs you to:
    Code (CSharp):
    1. Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal") Input.GetAxis("Vertikal"));
    And the error says that a comma (",") is expected here. Sure enough, there are no commas in this line, and there should be. Whenever you specify a list of arguments, like to new Vector2 in this case, you need commas between them. Also, I notice, your vertical axis is probably misspelled (unless you purposely changed the name of this axis in the Input Manager). So it should be:

    Code (CSharp):
    1. Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
     
    wisemanneedshelp and Schneider21 like this.
  3. DragondMa

    DragondMa

    Joined:
    Jul 16, 2021
    Posts:
    3
    Thank you for your reply.
    I changed it, but now there are two new errors:
    (9,13): The type or namespace „Rigidbody2d“ Couleur not be found
    (10,13) is the same with „Vectore2“

    Where is the problem now?
     
  4. max3210

    max3210

    Joined:
    Apr 19, 2020
    Posts:
    17
    It's just problems with spelling and capitalization.

    Change 'Rigidbody2d' into 'Rigidbody2D'
    and 'Vectore2' into 'Vector2'

    I'd suggest using autocomplete/intellisense in your editor and it will fill in the correct spelling & case for you.
     
  5. DragondMa

    DragondMa

    Joined:
    Jul 16, 2021
    Posts:
    3
    It‘s working now. Thanks to both of you.
     
    BrandyStarbrite and JoeStrout like this.