Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 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.     public float speed;
  12.  
  13.     public void Start(){
  14.  
  15.         StartCoroutine (Atirar ());
  16.     }
  17.  
  18.  
  19.     public IEnumerator Atirar(){
  20.         yield return new WaitForSeconds (delay);
  21.         List<BaseEnemy> enemiesInRadius =
  22.             GameManager.m_instance.GetEnemies (raioDeTiro, transform);
  23.         BaseEnemy target = new BaseEnemy ();
  24.         float distance = raioDeTiro;
  25.         foreach (BaseEnemy b in enemiesInRadius) {
  26.             if (Vector3.Distance (transform.position,
  27.                 b.transform.position) < distance) {
  28.                 distance = Vector3.Distance (transform.position,
  29.                     b.transform.position);
  30.                 target = b;
  31.             }
  32.        
  33.         }
  34.         if (target != null) {
  35.             GameObject novotiro =(GameObject)
  36.                 GameObject.Instantiate (tiro, transform.position,
  37.                     transform.rotation);
  38.             novotiro.GetComponent<Tiro> ().SetDano (m_dano);
  39.             float tbullet = distance / speed;
  40.             novotiro.transform.LookAt (target.transform.position);
  41.             Rigidbody rb = novotiro.GetComponent<Rigidbody> ();
  42.             rb.AddForce (novotiro.transform.forward * speed);
  43.         }
  44.         StartCoroutine (Atirar ());
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement