diff --git a/Assets/Attack.cs b/Assets/Attack.cs new file mode 100644 index 0000000..def48a0 --- /dev/null +++ b/Assets/Attack.cs @@ -0,0 +1,52 @@ +using UnityEngine; +using System.Collections; + +public class Attack : MonoBehaviour { + + GameObject bullet, bullet1, player; + public GameObject bulletPrefab; + DroneVision dVScript; + public bool tripleShot, currentlyShooting; + + // Use this for initialization + void Start () + { + dVScript = gameObject.GetComponent (); + currentlyShooting = false; + } + + // Update is called once per frame + void Update () + { + + if (dVScript.playerFound == true) + { + if (currentlyShooting == false) + StartCoroutine (shoot ()); + } + } + + IEnumerator shoot() + { + currentlyShooting = true; + Instantiate(bulletPrefab, transform.position+(transform.right*2), transform.rotation); + + if (tripleShot) + { + bullet = (GameObject)Instantiate(bulletPrefab, transform.position+(transform.right*2), transform.rotation); + bullet.transform.Rotate (0, 0, 45); + + bullet1 = (GameObject)Instantiate(bulletPrefab, transform.position+(transform.right*2), transform.rotation); + bullet1.transform.Rotate (0, 0, -45); + } + + //bullet.GetComponent ().parent = gameObject; + yield return new WaitForSeconds(1); + + if (dVScript.playerFound == true) + { + StartCoroutine (shoot ()); + }else + currentlyShooting = false; + } +} diff --git a/Assets/Attack.cs.meta b/Assets/Attack.cs.meta new file mode 100644 index 0000000..5cd1d1b --- /dev/null +++ b/Assets/Attack.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7b52c28dac10dc84a966cc30675d281e +timeCreated: 1478637467 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Bullet.cs b/Assets/Bullet.cs index f1b46b7..8872da0 100644 --- a/Assets/Bullet.cs +++ b/Assets/Bullet.cs @@ -11,9 +11,10 @@ void Start () { //_player = GameObject.FindGameObjectWithTag("Player").GetComponent(); //parentDir = transform.parent.transform.right; + lifetime = 2; Destroy(this.gameObject, lifetime); } - + // Update is called once per frame void Update () { diff --git a/Assets/Scripts/DroneVision.cs b/Assets/Scripts/DroneVision.cs index 13a1323..dee2744 100644 --- a/Assets/Scripts/DroneVision.cs +++ b/Assets/Scripts/DroneVision.cs @@ -10,8 +10,7 @@ public class DroneVision : MonoBehaviour //public delegate void FollowPlayerAction(); //public static event FollowPlayerAction FollowPlayer; - GameObject bullet; - public GameObject bulletPrefab; + public int bulletSpeed; public float visionRange; // range that a drone can find the player @@ -20,7 +19,7 @@ public class DroneVision : MonoBehaviour private static GameObject player; // player game object reference private CircleCollider2D droneCollider; // drone collider private DroneMovementAI droneMovement; - private bool isLookingForPlayer = false; + public bool isLookingForPlayer, playerFound = false; // Use this for initialization void Start () @@ -43,11 +42,6 @@ void OnTriggerEnter2D(Collider2D _player) isLookingForPlayer = true; StartCoroutine(LookForPlayer()); - if(shooting) - { - StartCoroutine(Attack()); - } - Debug.Log("start Looking"); } @@ -63,8 +57,8 @@ void OnTriggerExit2D(Collider2D _player) { //player = null; StopCoroutine(LookForPlayer()); - StopCoroutine(Attack()); isLookingForPlayer = false; + playerFound = false; } } @@ -78,6 +72,7 @@ IEnumerator LookForPlayer() if (Vector2.Distance(transform.position, player.transform.position) > 10) // constant will be replaced with attack range { droneMovement.StartFollowing(); + playerFound = true; } @@ -91,19 +86,7 @@ IEnumerator LookForPlayer() } } - - IEnumerator Attack() - { - bullet = (GameObject)Instantiate(bulletPrefab, transform.position, transform.rotation); - //bullet.GetComponent ().parent = gameObject; - yield return new WaitForSeconds(1); - - if (player != null) - { - StartCoroutine(Attack()); - } - } - + public static GameObject GetPlayer() { return player;