Hello good day guys! I have some i guess, well simple problem.
I cant seem to find how i would make the enemy runway from the player when low in health?
here is the code for the health:
{
public float enemyHealth = 25;
public GameObject DeadPrefab;
public void TakeDamage(float amnt)
{
enemyHealth -= amnt;
if(enemyHealth <= 0)
{
Instantiate(DeadPrefab, transform.position, transform.rotation);
{
Destroy(this.gameObject);
}
}
//survived!
if (enemyHealth <= 20)
{
//runawayfunctionhere
}
}
}
And Here is for the AI:
UnityEngine.AI.NavMeshAgent agent;
public Transform target;
public float extraRotationSpeed;
void Start ()
{
target = GameObject.FindWithTag("Player").transform;
agent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
}
void Update()
{
extraRotation();
agent.SetDestination(target.position);
}
void extraRotation()
{
Vector3 lookrotation = agent.steeringTarget - transform.position;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookrotation), extraRotationSpeed * Time.deltaTime);
}