Need help with my first code!

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();
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.

Welcome to the forums! Yes, we can help.

  • When pasting code, use the “Code:” button in the editing toolbar.

  • Don’t append a poll to your message. I know it kinda looks like you have to, but you don’t.

  • 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.

  • In this case that directs you to:

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:

Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
2 Likes

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?

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.

It‘s working now. Thanks to both of you.

2 Likes