Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Torre : MonoBehaviour {
- public int m_dano;
- public float delay;
- public float raioDeTiro;
- public GameObject tiro;
- public void Start(){
- StartCoroutine (Atirar ());
- }
- public IEnumerator Atirar(){
- yield return new WaitForSeconds (delay);
- List<BaseEnemy> enemiesInRadius = GameManager.m_instance.GetEnemies (raioDeTiro, transform);
- BaseEnemy target = new BaseEnemy ();
- float distance = raioDeTiro;
- foreach (BaseEnemy b in enemiesInRadius) {
- if (Vector3.Distance (transform.position, b.transform.position) < distance) {
- distance = Vector3.Distance (transform.position, b.transform.position);
- target = b;
- }
- }
- if (target != null) {
- GameObject novotiro =(GameObject) GameObject.Instantiate (tiro, transform.position, transform.rotation);
- tiro.GetComponent<Tiro> ().SetDano (m_dano);
- tiro.transform.LookAt (target.transform.position);
- Rigidbody rb = tiro.GetComponent<Rigidbody> ();
- }
- StartCoroutine (Atirar ());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement