private void createTarget() { try { // Get the information from the targetData float distance = targetData[currentTargetIndex].distance; float angularSize = targetData[currentTargetIndex].angularSize; // Psuedo-randomize spawn position Quaternion randAng = Quaternion.Euler(Random.Range(0, 10), Random.Range(-20, 20), 0); // Randomize angle Vector3 spawnPosition = (Vector3.up * 5) + (randAng * Vector3.forward * distance); // Destroy the old target if it exists destroyTarget(); // Create the new target, update it's angular size, and set it to be the currentTarget currentTarget = GameObject.Instantiate(targetPrefab, spawnPosition, Quaternion.identity) as GameObject; target currentTargetComponent = currentTarget.GetComponent <target>(); currentTargetComponent.Initialize(angularSize); // currentTargetIndex++; // Increase the target index for the next cycle. Debug.Log("Target Created."); } catch (System.IndexOutOfRangeException) { // Do Nothing Debug.LogWarning("Index Out of Range"); } }