Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. //Recieves call when a new enemy is added to the list
  2. public void NewEnemyDetected()
  3. {
  4. if(currentlyAttacking == null)
  5. {
  6. SelectEnemyToAttack();
  7. }
  8. }
  9.  
  10. //Recieves call when an enemy leaves the collider area
  11. public void EnemyGone()
  12. {
  13. SelectEnemyToAttack();
  14. }
  15.  
  16. //Will select an enemy from the array to attack
  17. private void SelectEnemyToAttack()
  18. {
  19. if(enemyObjects.Count > 0)
  20. {
  21. StopCoroutine(AttackEnemy());
  22. currentlyAttacking = enemyObjects.ElementAt(0);
  23. isAttacking = true;
  24. StartCoroutine(AttackEnemy());
  25. }
  26. else
  27. {
  28. currentlyAttacking = null;
  29. isAttacking = false;
  30. }
  31. }
  32.  
  33. //Partially hacked together attacking loop
  34. private IEnumerator AttackEnemy()
  35. {
  36. while(isAttacking)
  37. {
  38. Vector3 angle = currentlyAttacking.DetectedGameObject.transform.position - transformV.position;
  39. angle = angle.normalized;
  40. GameObject projectile = (GameObject)Instantiate(AttackType, transformV.position, transformV.rotation);
  41. BlasterAttack projectileAttack = projectile.GetComponent<BlasterAttack>();
  42. projectileAttack.OnCreation(10, player);
  43. projectile.GetComponent<Rigidbody>().AddForce(angle * 100);
  44. yield return new WaitForSeconds(1);
  45. }
  46. yield return false;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement