- Home /
How could I have a ball chooser menu?
I am making a ball rolling game, and I want to have different balls unlock as the character progresses. Some may be slightly quicker (or have different properties), and others may just look different.
How could I make a screen where the player could scroll though all of the balls, and they have a locked texture on them if they are locked, or be select able if not? When they are scrolling, a text box at the top of the screen should update to each ball, meaning that a ball is always selected. It would then display information about each ball, such as the name and speed.
I have all of the textures I need, but how could I implement a system to change between them in-game with their textures being visible (or locked where appropriate)?
Thanks, --Matt
Answer by konashadow · Dec 07, 2012 at 03:15 PM
If you make the texture of the ball a Global Variable, you can set the texture based on what ball they choose. You could make a global boolean variable for each ball to check whether it is unlocked or not. I'm not sure about how to make a scrolling menu, but you could allow the user to move the camera left or right. Then you can use this to see which one they hit:
if(Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit))
{
if(hit.transform.tag == "Ball")
{
if(hit.transform.name == "NormalBall")
{
//change the texture here
}
}
}
}
This will sense which ball they click. You can change the tag and the name, or take out the tag completely.
Thanks, but I am a bit of a Unity idiot, so could you give some example code for how to change the texture?
Thanks, --$$anonymous$$att
Check this page out: it gives instructions on how to change the texture of a material. By looking into the reference docs for material, you could also learn how to make a different material for each ball, and then switch those.
https://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial-mainTexture.html
You can set a global texture variable by declaring it at the beginning of the menu's script like this :
static var ballTexture : Texture;
Then you can use a code similar to what i wrote above and in place of where I put the //change texture here, you can do ballTexture = someTexture;
Next, in the ball's script, you can create another texture variable (doesn't have to be a global one) called texture and set it equal to ballTexture like this - (assu$$anonymous$$g the menu's script is called menu)
menu(script name).ballTexture(global variable) = texture
Hope this helps!
Your answer
Follow this Question
Related Questions
Quality-Settings Selections in scripting 1 Answer
How to make a Main Menu 3 Answers
One GameObjects Script Activating Another GameObjects Script 1 Answer
[Closed] MainMenu Script error 2 Answers
CoD 4 "weapon classes" 2 Answers