Iterator variable not increasing.

I’ve been trying to create a basic random asteroid field out of spheres and it was going so well until I realized that it never stopped generating. I used a while loop and made a variable representing the iterator (i) and did some code inside of it. I ended the while loop with an i++; but when i tested it, it didn’t seem as if the iterator increased. My code: `using UnityEngine;
using System.Collections;

public class AsteroidGeneration : MonoBehaviour {
%|-1008245593_1|%
public int objectCount;
%|10977004_2|%
%|1407053197_4|%
%|61866010_5|%

%|-1777223416_6|%

%|1768835771_7|%
Vector3 ranV = new Vector3 (Random.Range(0,spread), Random.Range(0,spread), Random.Range(0,spread));
%|-1190291132_9|%

%|-709725649_10|%
%|-1464503037_11|%
%|-1745120846_4|%
%|468739861_13|%
}`

I cant seem to solve this problem. Any help is appreciated!

If there is a problem with you seeing the code, here’s a picture:

Hi @heCAT,

Why you set i to zero every frame? are trying to make your own particle system ? If not then declare i out side update and then only once set i = 0 in Start or Awake Method.

In this case you get only see value in debug is value which set in public varialbe public int objectCount

if you want to create astroid field once only then replace while loop with if statement and declare I out side of Update function. so it will genrate each astroid one bye one each frame, and once rich to astroid count via objectCount it will stop genrateing new astroids around the sphere.