|
|
- using UnityEngine;
- using System.Collections;
-
- public class EnemyController : InteractableObject {
-
-
- public int health;
-
-
- private GameObject player;
- private Rigidbody2D playerRigid;
- public GameObject bullet;
- public float shotCoolDown = 0.5f;
- private float lastShotTime = 0.0f;
- private GameObject healthDisp;
-
- // Use this for initialization
- void Start () {
- healthDisp = GetComponentInChildren<ParticleSystem>().gameObject;
- player = GameObject.FindGameObjectWithTag("Player");
- playerRigid = player.GetComponent<Rigidbody2D>();
- }
-
- // Update is called once per frame
- void FixedUpdate () {
- if (Time.time - lastShotTime >= shotCoolDown) {
- lastShotTime = Time.time;
- shoot(Vector2.up);
- shoot(Vector2.down);
- shoot(Vector2.left);
- shoot(Vector2.right);
- }
-
-
- }
-
-
- private void shoot(Vector2 startVelocity) {
- GameObject bulletClone = (GameObject)Instantiate(bullet, transform.position, transform.rotation);
- MissileController bulletScript = bulletClone.GetComponent<MissileController>();
- bulletScript.startVelocity = startVelocity;
-
- bulletScript.targetPos = player.transform.position;
- bulletScript.target = player;
- bulletScript.targetRigid = playerRigid;
- bulletScript.ignoreList = GetComponentsInChildren<Collider2D>();
- bulletScript.spawningObject = this;
-
-
- bulletScript.enabled = true;
-
-
- }
-
- public override void shot() {
- health--;
- //Debug.Log("I got hit, health: " + health);
- if (health <= 0) {
- Destroy(gameObject);
- }
-
- Vector3 newScale = new Vector3(health / 10f, health / 10f, health / 10f);
- Debug.Log("new scale = " + newScale);
-
- healthDisp.transform.localScale = newScale;
- transform.localScale = newScale;
-
- }
- }
|