This script I’m trying to combine 2 functions first one is to have enemies to wander around the game and second is to have them attack player when it gets into distance, having problem with one of the lines asking for “:” instead of a semi-colon. Any help to figure out how to fix it is much appreciated.
var speed : float;
var isWalking : boolean = true;
var distance;
var target : Transform;
var lookAtDistance = 15.0;
var attackRange = 10.0;
var moveSpeed = 5.0;
var damping = 6.0;
private var isItAttacking = false;
function Start () {
randomRotation ();
}
function Update () {
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.yellow;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
{
this.transform.Translate(Vector3.forward * speed);
}
}
function FixedUpdate () {
rigidbody.AddForce (Vector3.down * 500);
}
function randomRotation () {
while(isWalking){
yield WaitForSeconds(Random.Range(5,10));
transform.eulerAngles = Vector3(0, Random.Range(0, 360), 0);
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack ()
{
isItAttacking = true;
renderer.material.color = Color.red;
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
the error code is this
Assets/Scripts-FPS/Enemy AI.js(47,58): BCE0044: expecting :, found ‘;’.
I’m new to java script been looking around for answers on vid tutorials and Unity answer, can’t seem to find one to solve my script error.