So, to anyone that's followed BergZergArcade's Hack-n-Slash tutorial should be familiar with this one...
and i've tried (and failed miserably) to make this into a custom action... so, i'm officially asking for help turning this into a custom action so that i can use it.
//BergZerg Arcade helped with this one
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxDistance;
private Transform myTransform;
void Awake()
{
myTransform = transform;
}
// Use this for initialization
void Start ()
{
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxDistance = 2;
}
// Update is called once per frame
void Update ()
{
Debug.DrawLine(target.position, myTransform.position, Color.red);
//Looking at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position),
rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
//Moving to the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
it works as a regular script but for the AI systems i've got to make, i need to control it much like you would with any Playmaker FSM... and it would be a lot simpler for what i need it for.
to note, i need this to be a "constantly on" action and the distance, speed and turning variables exposed so that i can control them with variables (or hard-coded in numbers.)