I am unable to continue as I keep getting this error “Parser error unexpected symbol “if””.
Assets/lePlayer.cs(13,64): error CS1525: Unexpected symbol `if’
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lePlayer : MonoBehaviour {
private int playerSpeed = 4;
private int jumpheight = 1200;
public bool isGrounded = false;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lePlayer : MonoBehaviour {
private int playerSpeed = 4;
private int jumpheight = 1200;
public bool isGrounded = false;
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, if);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("right"))
{
transform.position -= Vector3.left * playerSpeed * Time.deltaTime;
}
if (Input.GetKey ("left"))
{
transform.position -= Vector3.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKeyDown ("space") && isGrounded)
{
GetComponent<Rigidbody> ().AddForce (new Vector3 (0, jumpheight, 0), ForceMode.Force);
}
}
}
}
Still a offset with open"{“(7) and close”}"(8), they should be equal.
hence…
open"{“(7) and close”}"(7), - equal
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lePlayer : MonoBehaviour {
private int playerSpeed = 4;
private int jumpheight = 1200;
public bool isGrounded = false;
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, if);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("right"))
{
transform.position -= Vector3.left * playerSpeed * Time.deltaTime;
}
if (Input.GetKey ("left"))
{
transform.position -= Vector3.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKeyDown ("space") && isGrounded)
{
GetComponent<Rigidbody> ().AddForce (new Vector3 (0, jumpheight, 0), ForceMode.Force);
}
}
}
I have tried your code and it is still not working. I am getting the same error message. I am simply trying to follow this Youtube 2d game video . Please skip to 5:37 where he does the code. I’m not sure whats going on…please help.
( https://www.youtube.com/watch?v=dt16kqAUFuw
)
I believe he was just telling you to ad code when inserting here in the forums to make it more easy to try and detect where the problem resides. the fix is in the code I’ve inserted again below.
Still a offset with open"{“(7) and close”}"(8), they should be equal.
hence…
open"{“(7) and close”}"(7), - equal
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lePlayer : MonoBehaviour {
private int playerSpeed = 4;
private int jumpheight = 1200;
public bool isGrounded = false;
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, if);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("right"))
{
transform.position -= Vector3.left * playerSpeed * Time.deltaTime;
}
if (Input.GetKey ("left"))
{
transform.position -= Vector3.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKeyDown ("space") && isGrounded)
{
GetComponent<Rigidbody> ().AddForce (new Vector3 (0, jumpheight, 0), ForceMode.Force);
}
}
}
Dude stop.
The error was unexpected “if” keyword, not “missing }”. So he probably just didn’t scroll to the end of document when he copy-pasted the code here.
I even pointed out it’s location, passing “if” keyword as 3rd argument in Physics.Raycast().
You even copied modified version and didn’t read it. TWICE NOW.
COPY POSTED
Because I didn’t change anything other than adding a comment in void FixedUpdate();
You ALSO copied and didn’t read it.
You’re passing “if” keyword as third argument in Physics.Raycast when it should be “1f”.
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, if);
}
Should be:
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, 1f);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lePlayer : MonoBehaviour {
private int playerSpeed = 4;
private int jumpheight = 1200;
public bool isGrounded = false;
void FixedUpdate()
{
//what is this "if" doing here?
isGrounded = Physics.Raycast(transform.position, -Vector3.up, if);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("right"))
{
transform.position -= Vector3.left * playerSpeed * Time.deltaTime;
}
if (Input.GetKey ("left"))
{
transform.position -= Vector3.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKeyDown ("space") && isGrounded)
{
GetComponent<Rigidbody> ().AddForce (new Vector3 (0, jumpheight, 0), ForceMode.Force);
}
}
}
That was a reply for the @TSC spammer in this thread that copy pasted the same code 3 times now, not you. You’re fine. Just do what I wrote in the previus post.
Hold on @FMark92 he did have a offset then when it was fixed he got a different error even he said it say this now… how am I spamming? I’m trying to help? But ok.