- Home /
Unexcepted symbol
I am doing a 2D game, and it is telling there's an "Unexpected Error".
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed = 2f;
private Rigidbody2D c;
// Use this for initialization
void Start () {
rbp = GetComponent<Rigibody2d>;
}
// Update is called once per frame
void Update () {
}
void FixedUptade(){
float h = Input.GetAxis("Horizontal")
c.AddForce(Vector2.right * speed * hideFlags h);
}
}
Answer by SohailBukhari · Jun 08, 2017 at 05:48 AM
i documented your code where you was missing semicolons and there was many syntax errors in your code. scripting is an essential ingredient in all games. Even the simplest game needs scripts, to respond to input from the player and arrange for events in the gameplay to happen when they should. Beyond that, scripts can be used to create graphical effects, control the physical behavior of objects or even implement a custom AI system for characters in the game. Scripting is a skill that takes some time and effort to learn.
First learn scripting https://docs.unity3d.com/Manual/ScriptingSection.html
Read all scripting section in unity from above link and then code.
Modified Script :
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody2D c;
public float speed = 2f;
// Use this for initialization
private void Start()
{
// rbp = GetComponent<Rigibody2d>; You never declare rbp in your code
c = GetComponent<Rigidbody2D>(); //here you was not using proper way to GetComponent
}
private void FixedUpdate()
{
//float h = Input.GetAxis("Horizontal");// here you missed the semicolon
float h = Input.GetAxis("Horizontal");
//c.AddForce(Vector2.right * speed * hideFlags h);You never declare hideFlags in your code
c.AddForce(Vector2.right*speed*h);
}
}
Answer by SrBilyon · Jun 07, 2017 at 10:40 PM
I would recommend posting the entire error message, more importantly, the line number.
It might likely be line 21, you are missing an ending semi-colon. Also, you've misspelled "FixedUpdate", that could lead to problems as well.