🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Any C# coding pro's out there?

Started by
2 comments, last by Oddsocks.Studios 4 years, 10 months ago

Hello all... new hopeful game dev guy here with a question on scripting...

I'm looking to create a wave spawner to drop bombs, that begin a 5 second timer once they hit a surface, showing the user the time countdown, that once time runs out the bomb explodes complete with animation, the wave spawner then detects the bomb has gone and spawns a new one. Upon exploding the bomb is to leave dirt&debris on nearby objects/players, destroy the environment leaving a hole (think of worms bombs eating away at the landscape over time) as well as having a lethal zone where varying damage is inflicted on the player depending on proximity.

Wondering how to structure my code for this, the best approach to get my C# scripts done, all in 1 script or will it be done in multiple scripts ?

for example i have created the wave spawner, so the bombs now spawn from an empty game object, but where do i tell them to explode? in a new script? where do i tell the explosion to do damage to the environment? where do i tell the player to be hurt by the explosion on varying degrees of proximity? a new script for each or?


It's intended for unity 2D game setup for a phone game.

any advice would be much appreciated!

Thanks

Nick

Advertisement

I don't think you need a C# pro for this, per se. Among other things, the issues in question are more or less language-independent and aren't really specifically related to C#.

I haven't used Unity's new ECS system, but it sounds like you're using the older entity-component system.

What I'd suggest with respect to that system is that there's no one right (or in some cases even preferable) way to do the kinds of things you're asking about. You could put all or at least much the logic in a single script/behavior and have it control other game objects as needed. Or, you could distribute the behavior between multiple scripts/behaviors and have them communicate with each other in one way or another.

It sounds like there are quite a few different aspects to the logic/behavior you're after, so it would seem reasonable to me to try to encapsulate those aspects in different code modules (which could be scripts/behaviors) for greater modularity and easier testing in isolation. For example, dealing with Worms-style environment destruction seems like something that could (and perhaps should) be isolated from other aspects.

By taking this approach, you could work on each aspect one at a time, get them working in isolation, and then figure out how to get the different modules communicating with each other in the appropriate ways. (I haven't used Unity in a while, but I think I remember there being some sort of messaging system. You could also have different objects hold references to other objects as needed, or acquire them on demand using tags or names or whatever.)

Hi Zakwayda, thanks for your involvement on how i might approach this.

I really like your suggestion, about taking each action 1 at a time and testing & approving each bit in isolation, it doesn't seem so overwhelming that way. As a newbie to Unity and scripting i have no pre-conceived ways in my head about how actions should be scripted, but knowing you can do 1 action at a time and have the scripts talking to each other gives me a way in which i can build my game. It's useful to know because i didn't even know you could get the scripts to work together, and i like how it sounds.

Thanks, this is really helpful. I'll have to figure out how to get them to work together though now, which will be my next challenge.

Thank you!

Nick

This topic is closed to new replies.

Advertisement