I am recreating Flappy bird as my first project in unity (version 2021.3.6f1). I’m using Visual Studio to compile the C# script.
I get error CS1003 ‘,’ expected on (8,42)
My Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;
public FlightForce = new Vector2(0f, 10f);
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
rb.AddForce(FlightForce, ForceMode2D.Force);
}
}
}
>Solution :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;
public FlightForce = new Vector2(0f, 10f); // <--- you didn't provide the type here
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
rb.AddForce(FlightForce, ForceMode2D.Force);
}
}
}