2022-05-14 19:08:08 -04:00

47 lines
1.0 KiB
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()
{
StartCoroutine("Launch", 0.01f);
}
//TODO: find direction between spawn point and landing point
void GetLaunchDirection()
{
this.launchDirection = transform.position - landingPoint.position;
}
IEnumerator Launch()
{
yield return new WaitForSeconds(.1f);
gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * flyingSpeed;
}
public void IsShot()
{
Destroy(gameObject);
}
}