Parsing error
I've had multiple problems with the scripting as i'm completely new to it. I used the script from a tutorial and I keep getting a message saying there is a parsing error. Assets/clown.fbm/NewBehaviourScript.cs(1,12): error CS8025: Parsing error Any help what so ever would be greatly appreciated!
This is my script.
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform;
function Start(){
target = GameObject.FindWithTag("Keller").transform; //target the player
}
function Update () {
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 && distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
else if(distance<=range && distance>stop){
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
}
var target : Transform; var moveSpeed = 3; var rotationSpeed = 3; var range : float=10f; var range2 : float=10f; var stop : float=0; var myTransform : Transform; function Awake() { myTransform = transform; function Start(){ target = GameObject.FindWithTag("$$anonymous$$eller").transform; }
function Update () {
var distance = Vector3.Distance (myTransform.position, target.position);
if (distance <= range2 && distance >= range) {
myTransform.rotation = Quaternion.Slerp (myTransform.rotation,
Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * Time.deltaTime);
} else if (distance <= range && distance > stop) {
myTransform.rotation = Quaternion.Slerp (myTransform.rotation,
Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
} else if (distance <= stop) {
myTransform.rotation = Quaternion.Slerp (myTransform.rotation,
Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * Time.deltaTime);
}
}
} }
Edit your original question, select all of the code and press the 101010 button.
Answer by Jessespike · Jan 25, 2016 at 08:30 PM
function Awake() {
myTransform = transform;
function Start() {
target = GameObject.FindWithTag("Keller").transform; //target the player
}
The Awake function is missing a curly brace. " } "
Formatting and indenting the code neatly will make these issues obvious.
I added the curly bracket to the code and I'm still being told that there's an error?
I've gone through and seen if there were any brackets that were left without a pair and i couldn't see any
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
var myTransform : Transform; //current transform data of this enemy
function Awake(){
}
myTransform = transform;
function Start(){
target = GameObject.FindWithTag("$$anonymous$$eller").transform;
}
function Update () {
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 && distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
else if(distance<=range && distance>stop){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
}
function Awake(){
}
myTransform = transform;
function Start(){
target = GameObject.FindWithTag("$$anonymous$$eller").transform;
}
The curly brace is in the wrong place. myTransform = transform; needs to be inside of the function
function Awake(){
myTransform = transform;
}
Answer by ShadyProductions · Jan 25, 2016 at 08:35 PM
Half of the script is missing... This looks better.
public class NewBehaviourScript : MonoBehaviour {
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
var myTransform : Transform; //current transform data of this enemy
function Awake() {
myTransform = transform;
}
function Start() {
target = GameObject.FindWithTag("Keller").transform; //target the player
}
function Update () {
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance <= range2 && distance >= range) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
} else if (distance <= range && distance > stop) {
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
} else if (distance <= stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
}
}
After putting the code in it cleared the parsing error but then appeared with another error
Assets/clown.fbm/Follow camera.cs(2,20): error CS1519: Unexpected symbol `:' in class, struct, or interface member declaration