Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Assets/Attack.cs
Original file line number Diff line number Diff line change
@@ -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<DroneVision> ();
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<Bullet> ().parent = gameObject;
yield return new WaitForSeconds(1);

if (dVScript.playerFound == true)
{
StartCoroutine (shoot ());
}else
currentlyShooting = false;
}
}
12 changes: 12 additions & 0 deletions Assets/Attack.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/Bullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ void Start ()
{
//_player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
//parentDir = transform.parent.transform.right;
lifetime = 2;
Destroy(this.gameObject, lifetime);
}

// Update is called once per frame
void Update ()
{
Expand Down
27 changes: 5 additions & 22 deletions Assets/Scripts/DroneVision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ()
Expand All @@ -43,11 +42,6 @@ void OnTriggerEnter2D(Collider2D _player)
isLookingForPlayer = true;
StartCoroutine(LookForPlayer());

if(shooting)
{
StartCoroutine(Attack());
}

Debug.Log("start Looking");

}
Expand All @@ -63,8 +57,8 @@ void OnTriggerExit2D(Collider2D _player)
{
//player = null;
StopCoroutine(LookForPlayer());
StopCoroutine(Attack());
isLookingForPlayer = false;
playerFound = false;
}
}

Expand All @@ -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;

}

Expand All @@ -91,19 +86,7 @@ IEnumerator LookForPlayer()
}

}

IEnumerator Attack()
{
bullet = (GameObject)Instantiate(bulletPrefab, transform.position, transform.rotation);
//bullet.GetComponent<Bullet> ().parent = gameObject;
yield return new WaitForSeconds(1);

if (player != null)
{
StartCoroutine(Attack());
}
}


public static GameObject GetPlayer()
{
return player;
Expand Down