|
How can I make a game object a variable and then use a button to select it. Thanks.
(comments are locked)
|
|
Here is a simple script that draws a button for each Transform in an array of Transforms. If you attach this script to a GameObject, you will be able to populate the array of Transforms (named arrayOfTransforms) by dragging GameObjects onto the slot in the Inspector. The OnGUI function draws a button for each Transform in the array. If the user clicks the button, the Transform that corresponds to the button will be assigned to the variable chosenTransform so that you can manipulate it using code. Thanks, I know I have been hard.
Oct 17 '11 at 02:28 AM
Bones20
If you like it, upvote it! And then mark it as the accepted answer.
Oct 17 '11 at 02:29 AM
syclamoth
Marked it as correct, but could'nt upvote it, some sort of permission thing.
Oct 17 '11 at 03:19 PM
Bones20
(comments are locked)
|
|
Hello I'm assuming this would help, Say you want to select a GameObject called "Cube" in the hierarchy, then the following code would do that Of course all you need is to attach this script to a button now. Hope that helps, if not please be more specific. This is how you would cause a GameObject to be selected in the hierarchy. The question is how do you select a GameObject and manipulate it with a script using the GUI.
Oct 17 '11 at 12:44 AM
jahroy
(comments are locked)
|

Could you be more specific? What do you mean, 'make a game object a variable'? Do you mean, 'how do I reference a game object in a script'?
Also, please explain what you mean by 'use a button to select it'- do you mean in the editor, or in your game? 'selecting' is a high-level concept which can be implemented in any number of ways- try thinking through exactly what it is that you want to do, and then revise your question to be more... answerable.
Also, questions usually have at least one question mark in them? It kind of helps you parse the sentences.