Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Recieves call when a new enemy is added to the list
- public void NewEnemyDetected()
- {
- if(currentlyAttacking == null)
- {
- SelectEnemyToAttack();
- }
- }
- //Recieves call when an enemy leaves the collider area
- public void EnemyGone()
- {
- SelectEnemyToAttack();
- }
- //Will select an enemy from the array to attack
- private void SelectEnemyToAttack()
- {
- if(enemyObjects.Count > 0)
- {
- StopCoroutine(AttackEnemy());
- currentlyAttacking = enemyObjects.ElementAt(0);
- isAttacking = true;
- StartCoroutine(AttackEnemy());
- }
- else
- {
- currentlyAttacking = null;
- isAttacking = false;
- }
- }
- //Partially hacked together attacking loop
- private IEnumerator AttackEnemy()
- {
- while(isAttacking)
- {
- Vector3 angle = currentlyAttacking.DetectedGameObject.transform.position - transformV.position;
- angle = angle.normalized;
- GameObject projectile = (GameObject)Instantiate(AttackType, transformV.position, transformV.rotation);
- BlasterAttack projectileAttack = projectile.GetComponent<BlasterAttack>();
- projectileAttack.OnCreation(10, player);
- projectile.GetComponent<Rigidbody>().AddForce(angle * 100);
- yield return new WaitForSeconds(1);
- }
- yield return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement