using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed=1;
public int rotationSpeed=1;
// Use this for initialization
private Transform myTransform;
void Awake(){
myTransform = transform;
}
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Light1");
target = go.transform;
}
// Update is called once per frame
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.clear);
//Look at target
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position),rotationSpeed*Time.deltaTime);
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
This is my Enemy AI script. I have 3 Light. I want to enemy can automatically touch Light1 , Light2 and Light3. How can I do?
No. If something specific is not working Im glad to help, but I won't write your scripts. ;)
– StephanK