Created
May 6, 2020 08:31
-
-
Save SenpaiRar/07986079d329394a326c12037fae45bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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