I created an AI script, but it is having trouble. The enemy I'm putting the script on is supposed to be able to be spawned into the map multiple times, so i have to use a FindGameObjectsWithTag function with the tag of waypoint.
However it does not work and that's why I need help with it, Here is the script.
var waypoints : Transform[];
var Target : Transform;
var roam : enemyhealth;
var mybody : GameObject;
function Start() {
waypoints = GameObject.FindGameObjectsWithTag("waypoint");
roam = mybody.GetComponent(enemyhealth);
InvokeRepeating("check",0,10);
InvokeRepeating("MOVEIT",0,0.01);
}
function check() {
if(roam.isroaming==true){
var index : int = Random.Range(1,waypoints.length);
var thePrefab : Transform = waypoints[index];
Target = thePrefab;
}
}
function MOVEIT() {
if(roam.isroaming==true){
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime);
transform.Translate(Vector3.forward * Time.deltaTime);
}
}
I know that line 8, with
waypoints = GameObject.FindGameObjectsWithTag("waypoint");
Is not the right syntax, but I'm not sure how to implement this. Any help would be kind.
↧