Hello! I have this script for an enemy ai -
var target : Transform; //the enemy's target
static var moveSpeed : int = 100; //move speed
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
I’m trying to change the variable moveSpeed from another script. As you can see I’ve set it to be a static var, so I should be able to access it. This is the other script -
#pragma strict
function Update() {
var hit: RaycastHit; var forward = transform.TransformDirection (Vector3.forward);
var Cube : GameObject.Find("Cube");
if (Physics.Raycast (transform.position, forward, hit))
if(hit.collider.CompareTag("enemy")){
Debug.Log("Enemy Spotted!");
Cube.GetComponent.enemyai.moveSpeed = 10;
}else{
// Something blocking line of sight
}
Debug.DrawLine (transform.position, hit.point);
}
It’s just a script that triggers the action (change move speed to 10) when the player looks at the enemy. However, I am getting the error “‘;’ expected. Insert a semicolon at the end.” even though you can clearly see the semicolon. The error is on line 7 which is -
var Cube : GameObject.Find("Cube");
I have been looking for hours now to try and solve this. Maybe I need to do a different method all together, but I would really appreciate some help. Thank you so much! ![]()
Thank you so much you are awesome it works perfectly!
– JakeReis1