I have a GameObject with 4 children. Everytime the user hits the mousebutton the active child shoots away and the next child should become active. Now I remembered a code-fragment from the FPS tutorial Code (csharp): void SelectChilds( int index ) { for ( int i=0; i < transform.childCount; i++ ) { if ( i == index ) { transform.GetChild(i).gameObject.SetActiveRecursively( true ); } else { transform.GetChild(i).gameObject.SetActiveRecursively( false ); } } } Now my question is: Can I influence the way Unity arranges the children? Because now it starts with the 3th children, then the 4th, then the 1st... I already used this script for changing weapons and hadn't any problems with it.
I know but it's nice when a script is reusable... if I need the same script in another project but with 20 children for instance... But for now this solution works
Hoi, You can grab the list of children from unity when your script starts up. store that list. rearrange it to your likings. And then from then on use your own list, instead of asking unity for it. Doei, Lucas
You don't need separate scripts for that. You can just change the length of the array in the inspector. Rune
not really. But you seem to be the programmer type like me, not the designer type. I still find myself trying to do anything and all in code instead of just using the editor because "2 drag and drops are soooo much more evil than 20 lines of code". Have a tendency to waste time on finding complicated pure source solutions instead of just using the simplicity of the editor, but it is getting better. Years of training to do so I guess but the longer I use unity the more I love the fact that I can get behavior to work much faster through prefabs and setting it in the editor.
Correct again, I'm a programmer type I've just graduated in ICT (Information and Communication Technologies) where I've seen multiple programming languages. In those 3 years we've learned to program in such a way we could reuse our code as much as possible. In Unity I'm trying to do the same but indeed (like you said) I should use the simplicity of the Unity-editor instead.