init
This commit is contained in:
commit
e0a842f222
796 changed files with 361371 additions and 0 deletions
58
Assets/Scripts/EnemyBehavior.cs
Normal file
58
Assets/Scripts/EnemyBehavior.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
public class EnemyBehavior : MonoBehaviour
|
||||
{
|
||||
public float speed = 0;
|
||||
public static int enemyAmount;
|
||||
private bool alive = true;
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
enemyAmount++;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//StartCoroutine(walk(Random.Range(1, 3))); //grid base walk. Deprecated
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(alive)
|
||||
transform.position += Vector3.Normalize(GameManager.Instance.player.GetComponent<PlayerManager>().getClosestPlayer(transform.position).transform.position - transform.position) * speed * Time.deltaTime;
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
alive = false;
|
||||
GameManager.Instance.enemies.Remove(gameObject);
|
||||
if (GameManager.Instance.enemies.Count == 0)
|
||||
{
|
||||
GameManager.Instance.nextRound();
|
||||
}
|
||||
|
||||
//disable enemy capabilitiyes
|
||||
GetComponent<Collider>().enabled = false; //prevent player kill
|
||||
GetComponent<LookAtMovement>().enabled = false; //prevent rotation
|
||||
GetComponentInChildren<Animator>().SetBool("Die", true); //fire anim
|
||||
LeanTween.moveY(gameObject, transform.position.y + .5f, 0.1f).setEaseOutQuint();
|
||||
LeanTween.moveY(gameObject, transform.position.y - .5f, 0.35f).setEaseInQuint().setDelay(0.1f);
|
||||
LeanTween.moveY(gameObject, transform.position.y - 1, 1.1f).setEaseInQuint().setDelay(0.45f);
|
||||
|
||||
//add score
|
||||
GameManager.Instance.ScoreSys.AddScore(MyVars.enemyKillScore, true);
|
||||
|
||||
StartCoroutine(DestroyGameObject(1.5f));
|
||||
}
|
||||
|
||||
IEnumerator DestroyGameObject(float t)
|
||||
{
|
||||
yield return new WaitForSeconds(t);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue