Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by A.Haseeb · Sep 14, 2015 at 07:37 PM · c# tutorial

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);
      }
  }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave-Carlile · Sep 14, 2015 at 08:07 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image A.Haseeb · Sep 14, 2015 at 08:16 PM 0
Share

(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

avatar image GreenCore A.Haseeb · Sep 14, 2015 at 08:25 PM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image A.Haseeb · Sep 14, 2015 at 08:55 PM 0
Share

Ok brother

avatar image GreenCore A.Haseeb · Sep 14, 2015 at 08:57 PM 0
Share

Is it working now?

avatar image A.Haseeb GreenCore · Sep 17, 2015 at 08:17 PM 0
Share

No brother please help me

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges