Hello there, I have house with waypoints on the corners outside of the house and a big collider around the whole house, i’m making a script to send my enemies to the waypoints, once it hits the big collider that contains the whole house:
#pragma strict
var wayPoint : Transform[];
var distance = new Array();
function OnTriggerEnter(other : Collider)
{
if (other.gameObject.tag=="Slasher"){
var smallestDistance = [0,99999.99999];
for (var i = 0; i < wayPoint.length - 1; i++){
distance _= Vector3.Distance(wayPoint*.position, other.transform.position);*_
_ if (smallestDistance[1] > distance*){
smallestDistance[0] = i;
smallestDistance[1] = distance;
}
}
other.gameObject.GetComponent(“follow1.js”).target= wayPoint[smallestDistance[0]];
}*_
}
and this script is supposed to change the target of the zombie type and tag Slasher on the script “follow1.js”, from the Player to the next waypoint, which is the closest waypoint.
my follow1.js is this one:
var target : Transform; //the enemy’s target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float = 100;
var range2 : float = 100;
var stop : float = 1;
var myTransform : Transform; //current transform data of this enemy
function Awake() {
myTransform = transform; //cache transform data for easy access/performance
}
function Start() {
target = GameObject.FindWithTag(“Player”).transform; //target the player
animation.wrapMode = WrapMode.Loop;
}
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);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
animation.CrossFade(“Walk”);
} 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;
animation.CrossFade(“Walk”);
} else if (distance <= stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
this.animation.CrossFade(“Attack”);
}
}
which will be replaced for another script, with the same name.
However, i’m having two errors:
1. Assets/Scripst Colliders/BigCubeCollider.js(17,61): BCE0019: ‘target’ is not a member of ‘UnityEngine.Component’.
2. Assets/Scripst Colliders/BigCubeCollider.js(12,49): BCE0051: Operator ‘>’ cannot be used with a left hand side of type ‘float’ and a right hand side of type ‘Object’.
What should I do with it? please, help