Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 6, 2020 08:31
Show Gist options
  • Save SenpaiRar/07986079d329394a326c12037fae45bf to your computer and use it in GitHub Desktop.
Save SenpaiRar/07986079d329394a326c12037fae45bf to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StraightLiner : Enemy
{
GameObject Target;
Vector3 Direction;
public float Speed;
public float TimeTillDeath; //How long until self-destruct
public AudioClip DeathSound;
public int Damage;
public int Score;
private void Start(){
StartCoroutine(Lifespan());
Target=GameObject.FindWithTag("Player");
Direction = Target.transform.position-transform.position;
}
private void Update(){
transform.Translate(Direction.normalized*Speed*Time.deltaTime);
}
private void OnTriggerEnter(Collider col){
if(col.gameObject.tag == "Player"){
col.GetComponent<Entity>().TakeDamage(Damage);
Destroy(gameObject);
}
}
public override void TakeDamage(int T){
GameObject.FindGameObjectWithTag("GameController").GetComponent<Score_Manager>().AddScore(Score);
Target.GetComponent<AudioSource>().PlayOneShot(DeathSound, AudioConstant.AudioScale);
Destroy(gameObject);
}
public override void SpawnRoutine(Vector3 T){
Instantiate(this.gameObject, new Vector3(T.x,0,T.z), Quaternion.identity);
}
IEnumerator Lifespan(){
yield return new WaitForSecondsRealtime(TimeTillDeath);
Destroy(gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment