Hi in my space game i want to have a tab to next enemy but i cans seem to get the tab to work on my script i have the list showing my 3 baddys but when i hit tab there is noting going on any help would be amazing here is the code i have so far for it.
public class Targetting : MonoBehaviour {
public List<Transform> targets;
public Transform selectedTarget;
private Transform myTransform;
// Use this for initialization
void Start()
{
targets = new List<Transform>();
selectedTarget = null;
AddAllEnemies();
myTransform = transform;
}
public void AddAllEnemies()
{
GameObject[] go = GameObject.FindGameObjectsWithTag("enemy");
foreach(GameObject enemy in go)
AddTarget(enemy.transform);
}
public void AddTarget(Transform enemy)
{
targets.Add(enemy);
}
private void SortTargetsByDistance()
{
targets.Sort(delegate(Transform t1, Transform t2) {
return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position));
});
}
private void TargetEnemy()
{
if(selectedTarget = null)
{
SortTargetsByDistance();
selectedTarget = targets[0];
}
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Tab))
{
TargetEnemy();
}
}
}