- Home /
Determine what number roulette ball is on.
Hello! I am making a classic roulette game. I have a ball that falls on a wheel and the wheel rotates and stops. Once the wheel stops the ball stays secure in the number that it is in by small colliders on the sides. I was wondering how I would now determine what number the ball is laying on. I am fairly new to unity and I went looking on this forum but couldn't find any answers. Thank you.
i'd try foreach all coliders (37) after it stops spining to check which one has collision.
Answer by SoshJam · Apr 25, 2018 at 07:28 AM
In the Collider GameObjects for the roulette tiles, create a new collider extruding slightly from the bottom collider. Make sure you check IsTrigger and give it a tag. (I reccomend "RouletteTile")
Add a new script to the roulette tile game objects that contain the new collider. Call it "TileNumber" exactly like that. Inside the script, add public int number;
above the Start()
void. In the Editor, navigate to the script. For each tile, enter the number of the tile.
Then inside the script for the ball, test which collider it is inside. public int number = 0; void OnTriggerEnter(Collider other){ number = other.gameObject.getComponent<TileNumber>().number; }
Then you can access the number
variable for the ball from any gameObject!
If you found this answer useful, please award me with reputation!
Your answer
Follow this Question
Related Questions
Rotating an Arrow 2 Answers
How to make any dice have a given face(int) face up? 1 Answer
How to make an object(cylinder) always at the center of an object(Terrain)? 0 Answers
Camera rotating with physics based movement. 0 Answers
How not to make a RigidBody not go into ground when tilted foward? 1 Answer