using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySkullMovement : MonoBehaviour
{
public float speed;
private float distance;
private float step;
private Transform t;
private Transform target;
void Start()
{
t = transform;
target = GameObject.FindGameObjectWithTag( "Player" ).transform;
}
void Update()
{
Look();
CheckDistance();
step = speed * Time.deltaTime;
// Distance exist?
if ( distance != 0 && distance > 1 )
{
t.position = Vector3.MoveTowards( t.position, target.position, step );
}
}
void Look()
{
t.LookAt( target );
}
void CheckDistance()
{
distance = Vector3.Distance( t.position, target.position );
Debug.Log( distance );
}
}
↧