- Home /
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);}
}
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.
Answer by kmeboe · Oct 11, 2012 at 04:06 PM
Hello, and welcome to Unity Answers!
There are two problems with your code:
This is javascript rather than c#. Make sure this lives inside a .js file.
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);}
}
@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...
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
Follow this Question
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