Files

35 lines
855 B
C#

using UnityEngine;
public class FlyAtPlayer : MonoBehaviour
{
[SerializeField] Transform player;
Vector3 playerPosition;
[SerializeField] float projectileSpeed = 0.05f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
gameObject.SetActive(false);
}
void Start()
{
playerPosition = player.transform.position;
}
// Update is called once per frame
void Update()
{
MoveToPlayer();
DestroyWhenReached();
}
void MoveToPlayer()
{
transform.position = Vector3.MoveTowards(transform.position, playerPosition, Time.deltaTime * projectileSpeed);
}
void DestroyWhenReached()
{
if (transform.position == playerPosition)
{
Destroy(gameObject);
}
}
}