Hello everyone.
I have this script that does not work for the enemy. When the player approaches the enemy, it is not pursued. The enemy remains still in place.
What could be the problem?
Script of the enemy:
using UnityEngine;
using System.Collections;
public class EnemyInseguePlayer : MonoBehaviour {
public Transform player;
public float playerDistance;
public float playerXAxis;
public float moveSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
playerDistance = Vector3.Distance (player.position, transform.position);
if(playerDistance < 15f)
{
LookAtPlayer ();
}
if(playerDistance < 18f)
{
chase ();
}
}
void LookAtPlayer()
{
Vector2 playerXAxis;
playerXAxis = new Vector2(player.position.x, player.position.y);
}
void chase()
{
transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
}
}
↧