Assets/script/targeting.cs(22,31): error CS1525: Unexpected symbol `foreach’
I am writing a script to target monster in my game. But i ran across this problem that i just cant seem to find a solution to! Here have a look at the code… `using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class targeting : MonoBehaviour {
public List targets;
private Transform selectedTarget;
// Use this for initialization
void Start () {
targets = new List<Transform>();
selectedTarget = null;
AddAllEnemies();
}
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 TargetEnemy()
{
selectedTarget = targets[0];
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Tab))
{
TargetEnemy();
}
}
}
`
hence the part where it give me unexpected symbol is “foreach(GameObject enemy in go)”
i had already set up what go mean… just the foreach part that unity is having trouble with.