I m getting error please solve my errors I m beginner in unity,Getting error of :
Hi,I m beginner and I write script but got 2 errors which are shown below 1- Assets/Scripts/NedmethodScript.cs(1,254): error CS1041: Identifier expected 2-Assets/Scripts/NedmethodScript.cs(1,254): error CS8025: Parsing error
Please resolve my issue.I m working on Roll a ball Project as learning so kindly help me as soon as possible
using UnityEngine;
using System.Collections;
public class CubeScript : MonoBehaviour {
float MAX_SPEED = 1;
Vector3 speed = Vector3.zero;
public GameObject CameraGO;
// Use this for initialization
void Start () {
CameraGO.transform.position = this.transform.position -
new Vector3 (0, -11, 0);
}
// Update is called once per frame
void Update () {
if (speed.x > 0.01f) {
speed.x -= .01f;
}
if (speed.z > 0.01f) {
speed.z -= .01f;
}
this.transform.position += speed;
if (Input.GetKey (KeyCode.UpArrow)) {
speed = new Vector3(0,0,MAX_SPEED);
}
if(Input.GetKey(KeyCode.RightArrow))
speed = new Vector3(MAX_SPEED,0,0);
/*if(Input.GetKey(KeyCode.LeftArrow))
this.transform.position += new Vector3 (-speed, 0, 0);
if(Input.GetKey(KeyCode.DownArrow))
this.transform.position += new Vector3 (0, 0, -speed);
*/
float distance = Vector3.Distance (this.transform.position, CameraGO.transform.position);
//if(Mathf.Abs(this.transform.position.z - CameraGO.transform.position.z) > 60)
CameraGO.transform.position = this.transform.position -
new Vector3 (0, -11, 30);
}
}
Please edit your question and add your code there ins$$anonymous$$d of using screenshots. You can paste in your code and use the 101010 button to format it.
Answer by GreenCore · Sep 14, 2015 at 08:08 PM
I think the error you are talking about is in the first line of your code, which doesn't appear in your screenshots. Your first two lines should look like this:
using UnityEngine;
using System.Collections;
(Here is my code ) using UnityEngine; using System.Collections;
public class CubeScript : $$anonymous$$onoBehaviour { float $$anonymous$$AX_SPEED = 1; Vector3 speed = Vector3.zero; public GameObject CameraGO; // Use this for initialization void Start () { CameraGO.transform.position = this.transform.position - new Vector3 (0, -11, 0); }
// Update is called once per frame
void Update () {
if (speed.x > 0.01f) {
speed.x -= .01f;
}
if (speed.z > 0.01f) {
speed.z -= .01f;
}
this.transform.position += speed;
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.UpArrow)) {
speed = new Vector3(0,0,$$anonymous$$AX_SPEED);
}
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
speed = new Vector3($$anonymous$$AX_SPEED,0,0);
/*if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
this.transform.position += new Vector3 (-speed, 0, 0);
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow))
this.transform.position += new Vector3 (0, 0, -speed);
*/ float distance = Vector3.Distance (this.transform.position, CameraGO.transform.position); //if($$anonymous$$athf.Abs(this.transform.position.z - CameraGO.transform.position.z) > 60) CameraGO.transform.position = this.transform.position - new Vector3 (0, -11, 30); } }
While searching on net I found parsing error can be solve by adding curly at the end of script ,but my when i do this it does not solve my error infact the number of curly is even numbers
I notice the error says your script is called NedmethodScript but your code says CubeScript. Your script name should always match your class name. Either rename your script CubeScript or rename your class NedmethodScript. Watch out for the caps.
Answer by GreenCore · Sep 14, 2015 at 08:49 PM
Ok. Besides the class name issue, you missed a few "{" and "}".
I've fixed it, including the commented out sections which also had parsing errors.
using UnityEngine;
using System.Collections;
public class NedmethodScript : MonoBehaviour {
float MAX_SPEED = 1;
Vector3 speed = Vector3.zero;
public GameObject CameraGO;
// Use this for initialization
void Start () {
CameraGO.transform.position = this.transform.position - new Vector3 (0, -11, 0);
}
// Update is called once per frame
void Update () {
if (speed.x > 0.01f) {
speed.x -= .01f;
}
if (speed.z > 0.01f) {
speed.z -= .01f;
}
this.transform.position += speed;
if (Input.GetKey (KeyCode.UpArrow)) {
speed = new Vector3 (0, 0, MAX_SPEED);
}
if (Input.GetKey (KeyCode.RightArrow)) {
speed = new Vector3 (MAX_SPEED, 0, 0);
}
/*if (Input.GetKey (KeyCode.LeftArrow)) {
this.transform.position += new Vector3 (-speed, 0, 0);
}
if (Input.GetKey (KeyCode.DownArrow)) {
this.transform.position += new Vector3 (0, 0, -speed);
}*/
float distance = Vector3.Distance (this.transform.position, CameraGO.transform.position);
/*if (Mathf.Abs (this.transform.position.z - CameraGO.transform.position.z) > 60) {
//Do Stuff...
}*/
CameraGO.transform.position = this.transform.position - new Vector3 (0, -11, 30);
}
}
By the way, as Dave Carlile suggested, it would be nice if you could edit your original post and add your code there, to make your thread easier to read.
Your answer
Follow this Question
Related Questions
Why is this not working? 1 Answer
Enemy destroys player if scale is bigger 1 Answer
Saving data in a txt file from Input Field button? 0 Answers
A namespace can only contain types and namespace declarations..(39,14) 0 Answers
unity c# money system 2 Answers