2D Game Coding Error. I can't find where the error is. Help!!!
The error I receive:
Assets/Scripts/Player.cs(33,74): error CS8025: Parsing error
My Script:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float maxSpeed = 3f;
public float speed = 50f;
public float jumpPower = 150f;
public bool grounded;
private Rigidbody2D rb2d;
void Start()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce((Vector2.right * speed) * h);
if (rb2d.velocity.x > maxSpeed)
(
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))
Any help would be greatly appreciated!
Answer by HAPPY_SIR · Jan 22, 2017 at 03:59 PM
Go into the console tab and click the error. It will show you were the error is. And you have no } at the end of void FixedUpdate().
And you're not using :
void Update()
{
}
so it's pretty much useless
does that help?
Answer by DaNova · Jan 22, 2017 at 04:14 PM
It gave me an Ubexpected symbol "}" error, and the previous error still remains
what if you change
if (rb2d.velocity.x > maxSpeed)
(
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))
to
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y))
}
(add the {} symbols and take away the: ) )
what if you take away the last ) ? you have one at the start and to at the back .
I still receive the error
This is what it looks like now after the updates using UnityEngine; using System.Collections;
public class Player : $$anonymous$$onoBehaviour {
public float maxSpeed = 3f;
public float speed = 50f;
public float jumpPower = 150f;
public bool grounded;
private Rigidbody2D rb2d;
void Start()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce((Vector2.right * speed) * h);
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
well , the
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce((Vector2.right * speed) * h);
if (rb2d.velocity.x > maxSpeed) **<---- THIS**
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
} **THIS ONE IS THE ENDING OF THE UPDATE VOID**
still dosen't have a } at the end. That one that is out right now is only for the void FixedUpdate() . Try adding another } and make sure it (if (rb2d.velocity.x > maxSpeed) ) has 2. You can click on the symbols ({}) to see the other.
for example:
void Update()
{ (klick on this one and it will mark the other one so you know they are togheter)
}(or this one)
Voids if and those thing like that will always need one { and one }.
I tried my best to explain . Sorry if you don't understand.
I added it and it STILL gives me the error. I have absolutely no clue what it can possibly be. This is so annoying
Well , mabey try re writing the script? you might find something. :/
Your answer
