Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Torre : MonoBehaviour {
  6.  
  7.     public int m_dano;
  8.     public float delay;
  9.     public float raioDeTiro;
  10.     public GameObject tiro;
  11.  
  12.     public void Start(){
  13.  
  14.         StartCoroutine (Atirar ());
  15.     }
  16.  
  17.  
  18.     public IEnumerator Atirar(){
  19.         yield return new WaitForSeconds (delay);
  20.         List<BaseEnemy> enemiesInRadius = GameManager.m_instance.GetEnemies (raioDeTiro, transform);
  21.         BaseEnemy target = new BaseEnemy ();
  22.         float distance = raioDeTiro;
  23.         foreach (BaseEnemy b in enemiesInRadius) {
  24.             if (Vector3.Distance (transform.position, b.transform.position) < distance) {
  25.                 distance = Vector3.Distance (transform.position, b.transform.position);
  26.                 target = b;
  27.             }
  28.        
  29.         }
  30.         if (target != null) {
  31.             GameObject novotiro =(GameObject) GameObject.Instantiate (tiro, transform.position, transform.rotation);
  32.             tiro.GetComponent<Tiro> ().SetDano (m_dano);
  33.  
  34.             tiro.transform.LookAt (target.transform.position);
  35.             Rigidbody rb = tiro.GetComponent<Rigidbody> ();
  36.         }
  37.         StartCoroutine (Atirar ());
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement