Hi to all
I have Lerpz character(in 2DGemeplayTutorialProject) and attach enemyai script to it and this script not run in Lerp character
but when I attach this script to a Cube this script run
please help me to run this script on Lerpz character
and my enemyai script is here
using UnityEngine; using System.Collections;
public class enemyai : MonoBehaviour { public Transform target; public int movespeed; public int rotationspeed; private Transform mytransform; public int maxdistance; // Use this for initialization void Awake() { mytransform=transform; } void Start () { GameObject go=GameObject.FindGameObjectWithTag(“Player”); target=go.transform; maxdistance=2; }
// Update is called once per frame
void Update () {
Debug.DrawLine(target.transform.position,mytransform.position,Color.black);
//Look at target
Vector3 relativePos = target.position - mytransform.position;
mytransform.rotation=Quaternion.Slerp(mytransform.rotation,
Quaternion.LookRotation(relativePos),rotationspeed*Time.deltaTime);
//move toward target
if(Vector3.Distance(target.position,mytransform.position)>maxdistance)
mytransform.position+=mytransform.forwardmovespeedTime.deltaTime;
}
}