Hey Guys,
im trying to set a GameObject to another Object within a Loop.
I’ve got my variable definitions:
public GameObject PreviewObjectID0;
public GameObject PrefabObjectID0;
public GameObject PreviewObjectID1;
public GameObject PrefabObjectID1;
public GameObject PreviewObjectID2;
public GameObject PrefabObjectID2;
public GameObject PreviewObjectID3;
public GameObject PrefabObjectID3;
public GameObject PreviewObjectID4;
public GameObject PrefabObjectID4;
public GameObject PreviewObjectID5;
public GameObject PrefabObjectID5;
Later I’m trying to set those to some other Objects within a for loop (in the Update() function) based on a KeyDown:
for (int i = 0; i < 10; i++) {
if (revid1 == i) {
PlayerController.GetComponent<Buildingsystem>().previewrev = GameObject.Find("PreviewObjectID" + i);
PlayerController.GetComponent<Buildingsystem>().prefabrev = GameObject.Find("PrefabObjectID" + i);
toolSelected = -1;
break;
}
}
Now I got the problem that the GameObjects (PrefabObjectID1,2,3, … and PreviewObjectID1,2,3, …) will be set to empty …
Please help me, I’m kinda frustrated ![]()