- Home /
need help with lookat+arraylist
hi i have a little bit truble i explain the situation for better undertand im doing a tower defense game and i have made and array list of enemys when enter in trigger's tower but i dont know how made that the tower rotate with look at to the first enemy in the array of enemys
using UnityEngine; using System.Collections;
public class playerLogic : MonoBehaviour {
public int health;
float shotTimeCounter;
Transform shotTarget;
ArrayList enemiesNames = new ArrayList();
// Use this for initialization
void Start ()
{
shotTimeCounter = 0;
}
// Update is called once per frame
void Update ()
{
//health logic
if(this.health <=0)
{
Destroy (this);
}
//position logic
//ROTATION LOOKAT LOGIC
transform.LookAt(shotTarget);
//health logic
if(this.health <=0)
{
Destroy (this);
}
//shot logic
if (shotTimeCounter >= 2)
{
//do a shot function that shot in the order of the array
shotTimeCounter = 0;
}
shotTimeCounter += Time.deltaTime;
}
//detection logic
void OnTriggerEnter(Collider other)
{
if (!enemiesNames.Contains(other.name)) enemiesNames.Add(other.name);
}
void OnTriggerExit(Collider other)
{
if (enemiesNames.Contains(other.name)) enemiesNames.Remove(other.name);
}
}
thx for your time
Comment
Your answer
Follow this Question
Related Questions
How do I make a turret for a unity game? 2 Answers
how to limit axis of rotation when looking to a target 1 Answer
Jittering Camera 3D ,Jittery 3D camera using a LookAt() on an object 0 Answers
GameObject rotates away from camera when using ScreenToWorldPoint 0 Answers
Populate array on Start() and accessing it on Update()...how to? 4 Answers