I used the following code with foreach… and when I run the game… my computer freezes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour {
public GameObject enemy;
// Use this for initialization
void Start () {
foreach (Transform child in transform) {
GameObject enemyObj = Instantiate (enemy, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
enemyObj.transform.parent = transform;
}
}
// Update is called once per frame
void Update () {
}
}
It isn’t the first time I used foreach and that happens…