Creación de bala y que las torres les dispararan a los enemigos.
¿Que se va a hacer?
Implementación de la barra de salud y hacer que los enemigos ataquen a las torres.
Si se terminan estos avances oportunamente se espera seguir avanzado con el proyecto en mejoras de lo que ya se hizo y agregando nuevas funciones.
¿Que problemas hubo?
Organización de tiempo.
Nuevo código de unidad
Code: Select all
public GameObject ruta;
private int indice;
private Vector3 posicion_inicial;
private Vector3 posicion_siguiente;
private float vel = 2;
private float distancia_punto = 0.2f;
void Start() {
posicion_inicial = this.transform.position;
posicion_siguiente = ruta.transform.GetChild(0).position;
}
void Update() {
Vector3 dir = posicion_siguiente - this.transform.position;
this.transform.position += dir * vel * Time.deltaTime;
if (dir.magnitude <= distancia_punto)
{
if (indice + 1 < ruta.transform.childCount)
{
indice++;
posicion_siguiente = ruta.transform.GetChild(indice).position;
Debug.Log("xs" + posicion_siguiente.x + "ys" + posicion_siguiente.y + "zs" + posicion_siguiente.z);
}
else
{
indice = 0;
this.transform.position = posicion_inicial;
posicion_siguiente = ruta.transform.GetChild(0).position;
}
}
Code: Select all
public GameObject enemigo;
private bool esta_activa;
private float distancia_umbral = 4;
public bool Esta_activa
{
get
{
return esta_activa;
}
set
{
esta_activa = value;
}
}
void Start () {
}
void Update () {
enemigo = BuscarEnemigoCercano();
if (enemigo != null)
{
Disparar();
Debug.DrawLine(this.transform.position, enemigo.transform.position, Color.white);
}
}
void Disparar()
{
GameObject obj = (GameObject)Instantiate(GameObject.Find("bala"),this.transform.position, Quaternion.identity);
Bala bala = obj.GetComponent<Bala>();
bala.ActivarBala(this);
}
GameObject BuscarEnemigoCercano()
{
ArrayList enemigos = PoolingdeUnidades.unidades;
GameObject temp;
foreach (Object item in enemigos)
{
temp = (GameObject)item;
if (Vector3.Distance(temp.transform.position, this.transform.position) < distancia_umbral)
{
return temp;
}
}
return null;
}
Code: Select all
private GameObject objetivo;
private float velocidad = 2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 direccion;
if (objetivo != null)
{
direccion = objetivo.transform.position - this.transform.position;
this.transform.position += velocidad * direccion * Time.deltaTime;
}
}
public void ActivarBala(Torre torre)
{
objetivo = torre.enemigo;
}