46 lines
964 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public Transform landingPoint;
public float flyingSpeed;
Vector3 launchDirection;
private void Update()
{
//Debug.DrawRay(transform.position, launchDirection, Color.red);
}
public void SetLandingPoint(Transform landingPoint)
{
this.landingPoint = landingPoint;
gameObject.transform.LookAt(landingPoint);
GetLaunchDirection();
}
void SpawnFinished()
{
Launch();
}
//TODO: find direction between spawn point and landing point
void GetLaunchDirection()
{
this.launchDirection = transform.position - landingPoint.position;
}
void Launch()
{
gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * flyingSpeed;
}
public void IsShot()
{
Destroy(gameObject);
}
}