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 float speed;
- 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);
- novotiro.GetComponent<Tiro> ().SetDano (m_dano);
- float tbullet = distance / speed;
- novotiro.transform.LookAt (target.transform.position);
- Rigidbody rb = novotiro.GetComponent<Rigidbody> ();
- rb.AddForce (novotiro.transform.forward * speed);
- }
- StartCoroutine (Atirar ());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement