My Marble / Ball / Ammunition Manager Approach

Hey there, I’m new here. And new using Unity.

I’ve read alot of your posts since starting out in unity3d and many times I find more then one solution to what I’m trying to research. So kudos to all you active posters. I’m an as3 guy so , so the conversion is more then smooth!

I have some logic that’s specific that I would like to see if someone can point me in the right direction to resolving

I am building a table-top marble game with similarities to a standard pinball machine. I have the physics working quite well in my prototype and have been using a single marble while fine-tuning the physics.

I have now reached a point where I need to add some type of ball manager logic to see the amount of marbles left. the game will have extra marbles added (extra balls) . And maybe the manager can distribute a ball to the start of gameplay position.

So , I have a few ideas but keep failing when I try different approaches to this.
The approach ( + problems I’m having are ) the colliders check to see if that colliding rigid type, which means when I creative marbles of the same variable name , I don’t know how to control a specific marble.

Should I make some array of the balls in play and check if a current one is being collided with? it that to heavy?
Or maybe Should I use some global variable and re reference that?
I was thinking I just make some prefab of the marble and load it up when needed, but then my colliders don’t work anymore as unity adds (clone) to the name etc

I just can’t seem to get this step right, and would like to see how you would approach it. Or if maybe you know where there is some information or tutorial or old post that could help me out I’d appreciate the help

You’re only playing the game with one marble at a time right?
So if the marble ‘dies’, you can just update the position, rotation and force of the same marble in the new position to start with another marble, meanwhile sending a message to your marble counter that one has been subtracted.
Hope that helps?
-TT

hi again TT!

sorry I didn’t mention that. All marbles need to remain in gameplay stage

Ah, so you’re basically using multiple ‘players’ but only one player is active at a time?

So when you switch to a different marble, the camera needs to follow that new marble and also the input controls are controlling the new marble.

There’s different ways to do it.

The easy/messy way:
Attach your movement control script to all the marbles but turn the scripts on/off at runtime. Only one active at a time. This is an ugly hack, but it should work. Don’t forget to switch targets in your camera follow script also.

The better/harder way:
Make one script for input controls and don’t attach them to your marbles but to an empty game object. In this scripts, the ‘target’ should refer to your current active marble gameObject. Now, when the game object changes, you’re just updating the script to follow the new target.
Just like the smoothfollow.js does with the camera.

Let me know if that helps…

Thanks again for your reply. I’m getting there I think.

So , I’m not using neither a keyboard controller nor camera movement. The gameplay is all built in physics/ gravity based stuff.

I have a plunger to launch my active marble into gameplay. From there , the gameplay is gravity. I’d it touches my ‘bumpers’ I add points , if it falls into a hole, that current marbles gameplay sessions is over. I also have main reset, that lets you restart gameplay with the current marble as no result was reached.

Now what I would like is send out / broadcast a message to some script. " this marble’s session is now over. Please find me the next marble to play with, and place it game play start position, and tell everyone listening that this is current marble in gameplay"

So taking what your suggestion , I need some type of script attached to an empty game object that decides which is the active marble and targets it alone

And should that be ‘broadcasting’ it ?
(I’m not sure how to explain it correctly)

Like should the marble itself have a var like ActiveMarble that I check?

Or should i make a var like CurrentMarble and make an array of all balls and always fill that with which marble is current in gameplay using a numerator like approach to check which marble is active?

Should I always be referring to that when I’m checking my script gameplay colliders (which btw add points on contact) ? And in that case should collision be based by the colliding marble’s name or type (ie. rigidbody) or should it be referring to only that activeMarble variable I created before, and should it check back to the currentMarble script we mentioned before?

thanks for your help!

Send me an email at UnityPrefabs@gmail.com, I have the perfect script for you.
-TT