- Home /
2D platformer- getting errors I don't understand (c#)
Hello, I am trying to make a platformer without using premade character controllers. I am running into a lot of errors when I try to run the code, most of which are CS1519: Unexpected symbol (although I've been checking and the symbols look fine!). Here is my code:
Animator anim;
Rigidbody2D playerRigidBody2D;
GameObject gameObject;
// Use this for initialization
void Start () {
anim = GetComponent <Animator> ();
anim.SetBool ("jump", false);
anim.SetBool ("go", false
gameObject= GetComponent<Robin>();
playerRigidBody2D = GetComponent<Rigidbody2D> ();
}
//This huge pile of code is the Move function.
void Move () {
Vector3 direction = Vector3.zero;
//this is jump
if (Input.GetKey (KeyCode.UpArrow) == true) {
direction.y += 0.1f;
anim.SetBool ("jump", true);
}
else {
anim.SetBool ("jump", false)
}
if (Input.GetKey (KeyCode.RightArrow) == true) {
direction.x += 0.1f;
anim.SetBool ("go", true);
}
else if (Input.GetKey (KeyCode.LeftArrow) == true) {
direction.x -= 0.1f;
anim.SetBool ("go", true);
}
else {
direction.x= 0f;
direction.y=0f;
anim.SetBool ("go",false);
//That turns everything off if nothing is being pressed.
}
gameObject.transform.Translate (direction);
void FixedUpdate ()
{
Move ();
}
}
Any help would be greatly appreciated!
P.S: The errors are: 15,22): error CS1525: Unexpected symbol gameObject' (31,25): error CS1525: Unexpected symbol
}' (37,20): error CS1525: Unexpected symbol else' (41,28): error CS1519: Unexpected symbol
else' in class, struct, or interface member declaration (42,36): error CS1519: Unexpected symbol =' in class, struct, or interface member declaration (43,36): error CS1519: Unexpected symbol
=' in class, struct, or interface member declaration (44,38): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration (47,48): error CS8025: Parsing error
Thank you!
Answer by KiraSensei · Dec 08, 2014 at 04:32 PM
Hello !
First I advise you to rename your variable "gameObject" because it already is an existing variable (it is the game object that attaches this script).
anim.SetBool ("jump", false)
should be
anim.SetBool ("jump", false);
And you declared
void FixedUpdate ()
{
Move ();
}
Inside the "Move" method, it should be after the last bracket.
Tell me if you have errors after these modifications.
Hello!
I did what you suggested and fixed the anim.SetBool error. I also got rid of the fixed update and renamed the gameObject variable Robin. The error I am getting is error CS1525: Unexpected symbol `Robin'(which is the name of the game object in the hierarchy). So my question is, how do I get Unity to use the game object?
By the way, thank you for answering my post!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error (Read Only) 1 Answer
Simple collision detection C# 2D 1 Answer
How do I fix my compiler errors? (Probably simple to solve) 0 Answers
Make a 2D jump? 0 Answers