- Home /
change various Prefabs (primitives) with a Gui.Button // switching Prefabs
i like change my prefabs using a Gui.Button //i'm using two button :
[<<] // Previus prefab [>>] // Next Prefab
this for customize menu
how can i do this?
Answer by SCZ · May 19, 2011 at 02:04 AM
This is mainly untested psudocode. I'm normally using c# so i hope my translation is not too bad.
- We put all or prefabs that we want to scroll through in a public gameobject array: GameObject[] myPrefabs. 
- To loop through we declare an integer called an "activeIndex". This is the one thats incharge of letting oyu know which prefab is currently being selected. 
- Then the code to do it: - var myPrefabs:GameObject[]; var ActiveIndex:int = 0; var ActivePrefab:GameObject = null; function OnGUI(){ if( 0 != ActiveIndex){ if (GUI.Button (Rect(0,0, 50,50), "Prev")){ ActiveIndex--; ActivePrefab = myPrefabs[ActiveIndex]; } } if( myPrefabs.Length - 1 > ActiveIndex){ if (GUI.Button (Rect(50,0, 50,50), "Next")){ ActiveIndex++; ActivePrefab = myPrefabs[ActiveIndex]; } } }
Answer by cj_cast · May 19, 2011 at 03:46 PM
hello i m test the script and have wrong i'm work in the same script how can i do ? for example i'm have 4 prefab: geometry_a, geometry_b geometry_c, geometry_d
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                