I have a map controller script (c#),
Generation of the map in setup():
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
GameObject go = (GameObject)Instantiate (prefab);
go.transform.position = new Vector2 (j, i);
go.isStatic = true;
go.SetActive (false);
gos.Add (go);
}
}
Calculating if I should activate a tile or not in update():
foreach (GameObject go in gos) {
if (go.transform.position.x > left-treshold && go.transform.position.x < right+treshold && go.transform.position.y < top+treshold && go.transform.position.y > bottom-treshold) {
//Debug.Log ("I am visible!");
if(!go.activeSelf){go.SetActive (true);}
} else {
if(go.activeSelf){go.SetActive (false);}
//Debug.Log ("I am NOT visible!");
}
}
With a width and height of 200, I only get ~30fps. What can I do to optimize my program?
I’m very new to c# and I’d like to learn as much as possible. Thanks ![]()