I’ve written a version of this script once before as I learned from Imphenzia on Youtube. Now I’m rewriting it again, the script is going exactly like my last script only I keep getting the error code CS1002. I’ve checked the semicolons, then i checked the line of code and it looks normal. I don’t know what to do. Please help me.
Here’s the error message: Assets\Script\Player.cs(32,38): error CS1002: ; expected
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private bool jumpKeyWasPressed;
private float horizontalInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Check if space key is pressed down
if (Input.GetKeyDown(KeyCode.Space))
{
jumpKeyWasPressed = true;
}
horizontalInput = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
if (jumpKeyWasPressed)
{
GetComponent<Rigidbody>()AddForce(Vector3.up * 5, ForceMode.VelocityChange);
jumpKeyWasPressed = false;
}
}
}
I think it’s more of just not being careful and not looking at what you’ve typed because you’ve missed the period (.) but yet you’ve used that correctly elsewhere (Line 20, Line 25 etc) so are you sure it’s lack of experience?
GetComponent<Rigidbody>()AddForce
to GetComponent<Rigidbody>().AddForce
Well this is my first unity project so I dunno if that makes me inexperienced or not but I’m sorry about bothering you because you were right, I added the period and the error went away, I feel silly. Well thanks for the help. I can’t believe it was a period. I swear I looked over it a billion times but I guess I was only looking in specific spots and not the whole line of code. Thanks again for replying. I hope you have a wonderful day/night .
I’m not trying to make you feel bad but for things like this, all you really need to do is stop and look at the line carefully. It’s certainly quicker than having to reach for a forum for a typo.
If you are in doubt, delete the line and type it again. You’re likely to not make the same mistake twice.
Yeah your all good I don’t feel bad at all. But I’ll take the advice along with maybe taking a break from my computer lol as I searched up dozens of web pages, and I deleted parts of the sentence and did it again. But again thanks for the advice, and next time I’ll to walk away and come back before I post on a forum because apparently all I needed was a break.