Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by CYVISUALEFFECTS · Oct 11, 2012 at 01:49 PM · c#error

Why am I getting a parsing error?

Why am I getting a parsing error??

     //target to follow var target : Transform;
 
 //Checks his position, used to follow the target var pos : Transform;
 
 //Ray variables (Length... etc.) var rayLength : float = 3;
 
 //Movement, speed etc. var speed : float = 2;
 
 //You can move if he is not being looked at var move : boolean = false;
 
 //I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it function FixedUpdate() { transform.position.y = 2; }
 
 function Update() { //Setting up Raycast variables for simple object avoidance var fwd = transform.TransformDirection (Vector3.forward); var hit : RaycastHit;
 
     //If you are looking at the object...
     if (renderer.isVisible)
     {
     move = false;
     }
 
     //If you are NOT looking at the object...
     if(!renderer.isVisible)
     {
     move = true;
     }
 
     //If you are not looking at the object...
     if(move)
     {
     //Make him look at the target
     transform.LookAt(target);
     //Always follow the target
     pos.position += pos.forward * speed * Time.deltaTime;
     }
 
     //If he is 3 units away from something, move right (Works if you are not looking at the object)
     if (Physics.Raycast (transform.position, fwd, rayLength) && move)
     {
     Debug.Log("Something ahead, moving");
     transform.Translate(Vector3.right * 3 * Time.deltaTime);}
         
      }
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 Graham-Dunnett ♦♦ · Oct 11, 2012 at 01:58 PM 0
Share

No idea. When I copy-paste your code I get BCE0005 errors because your move, target, pos, speed, fwd, and rayLength variables are not declared anywhere.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kmeboe · Oct 11, 2012 at 04:06 PM

Hello, and welcome to Unity Answers!

There are two problems with your code:

  1. This is javascript rather than c#. Make sure this lives inside a .js file.

  2. Your variable declarations were all commented out.

Here's the fixed code. I also cleaned up the tabs a little bit.

 //target to follow 
 var target : Transform;
 
 //Checks his position, used to follow the target 
 var pos : Transform;
 
 //Ray variables (Length... etc.) 
 var rayLength : float = 3;
 
 //Movement, speed etc. 
 var speed : float = 2;
 
 //You can move if he is not being looked at 
 var move : boolean = false;
 
 //I had problems with my model sinking into the floor, adjust this variable if you need it, or remove it function FixedUpdate() { transform.position.y = 2; }
 
 function Update() { //Setting up Raycast variables for simple object avoidance 
     var fwd = transform.TransformDirection (Vector3.forward); 
     var hit : RaycastHit;
 
     //If you are looking at the object...
     if (renderer.isVisible)
     {
         move = false;
     }
 
     //If you are NOT looking at the object...
     if(!renderer.isVisible)
     {
         move = true;
     }
 
     //If you are not looking at the object...
     if(move)
     {
         //Make him look at the target
         transform.LookAt(target);
         //Always follow the target
         pos.position += pos.forward * speed * Time.deltaTime;
     }
 
     //If he is 3 units away from something, move right (Works if you are not looking at the object)
     if (Physics.Raycast (transform.position, fwd, rayLength) && move)
     {
         Debug.Log("Something ahead, moving");
         transform.Translate(Vector3.right * 3 * Time.deltaTime);}
 
      }
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 code-blep · Oct 12, 2012 at 12:33 PM 1
Share

@kmeboe - This poster seem to fail to respond and reward our time. If he just takes and runs with the answer with no effort or acknowledgement. I have advised him about what he should do with answers and suggestions in another post...

avatar image kmeboe · Oct 12, 2012 at 05:20 PM 0
Share

Indeed...it's frustrating to spend time helping someone, and not hear any feedback in return.

Part of it may just be his newness to Unity Answers. Hopefully your prodding will help him change his ways. :)

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

cant kill more than one enemy C# 2 Answers

C# Script error (error CS8025: Parsing error) 0 Answers

C# script error. 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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