ltrout

EnemyAttack

Dec 24th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using PlayerInfo;
  5. using Shell;
  6.  
  7. namespace EnemyInfo
  8. {
  9.     public class EnemyAttack : MonoBehaviour
  10.     {
  11.         public float timeBetweenAttacks = 0.75f;
  12.         public float attackDamage;
  13.         public Rigidbody Shell;
  14.         public Transform FireTransform;
  15.         public AudioSource ShootingAudio;
  16.         public AudioClip Firing;
  17.         public float LaunchForce;
  18.  
  19.         GameObject player;
  20.         PlayerHealth pHealth;
  21.         EnemyHealth eHealth;
  22.         PlayerAttack pShoot;
  23.         EnemyAttack eShoot;
  24.         float timer;
  25.         EnemyMovement eMove;
  26.         ShellExplosion sExplo;
  27.  
  28.  
  29.         void Awake ()
  30.         {
  31.             player = GameObject.FindGameObjectWithTag ("Player");
  32.             pHealth = player.GetComponent<PlayerHealth> ();
  33.             eHealth = GetComponent<EnemyHealth> ();
  34.             eMove = GetComponent<EnemyMovement> ();
  35.             sExplo = GetComponent<ShellExplosion> ();
  36.  
  37.         }
  38.  
  39.         void Update ()
  40.         {
  41.             timer += Time.deltaTime;
  42.  
  43.             if (timer >= timeBetweenAttacks && eMove.inRange && eHealth.CurrentHealth > 0)
  44.             {
  45.                 Attack ();
  46.             }
  47.  
  48.         }
  49.  
  50.         void Attack ()
  51.         {
  52.             LaunchForce = Random.Range (15, 30);
  53.  
  54.             timer = 0f;
  55.  
  56.             Rigidbody shellInstance = Instantiate (Shell, FireTransform.position, FireTransform.rotation) as Rigidbody;
  57.  
  58.             shellInstance.velocity = LaunchForce * FireTransform.forward;
  59.  
  60.  
  61.         }
  62.     }
  63. }
Add Comment
Please, Sign In to add comment