![]() ![]() Example: SnakeGame is simply the container for the games items, so to me it wouldn't make sense for SnakeGame to Inherit because all of the objects used in SnakeGame are simply what it "has", and not what it "is". One thing I would like to point out, is I am not using Inheritance in any of my code, the reason being is that there are no relationships with any of the games objects, Inheritance should be used on a "is a" basis, and all of my objects are on a "has a" basis. I have also introduced Method Overloading, you'll see how it is used in the helper scripts. I like my results, because not only have I made reusable code with the helper scripts, but it allowed me to reduce the overall number of scripts for the game. I would really be interested in everyone's thoughts as to how I have removed duplicate code and made it more useful. To All: The pdf and project file links have been updated at the start of this thread I agree completely Noctys, so I have gone back through, looked at some areas you mentioned and re-programmed them in a much more logical manner. Either way though thanks for this tutorial as it did help me out a lot on the Unity end of things.Ĭlick to expand. It would be really good for you, and future reader of this tutorial, if you were to go back and create this using good OO deign principles. Anytime you find yourself cutting and pasting code you should be asking: Could I create a base-class or a method to do this? I agree that it makes it easier to read but not when it comes to maintaining code. In a previous post you said: "used some repeat code, mainly just to keep the objects methods to themselves only, and well its also a way I consider a simpler style of programming, by having similar functions written out, but keeping them within each objects class." Using singletons for things like that instead of objects makes programming more difficult in the long run. ![]() Especially with items like Lives Scores, ScreenBorder ScreenField, also with the movement of the snake. That being said there is a TON of repeat code that could be moved to methods and/or base classes. Thanks for this code - it helped me out with learning how to program games in Unity only using code. The code is clean and well commented, so you shouldn't have any issues following along, but please let me know if you do have any questions, I'll be glad to help you as much as I can. The goal is to show you how singletons work, and how you can use programming to build things at run time. Here are the 4 sounds used in the game: 2D Snake Game SoundsĪlthough I recommend building everything from the documentation, if your interested in the project files, you can get them here: 2D Snake Game Project Files Here is the tutorial documentation: 2D Snake Tutorial What you'll be doing is building the game from 4 sounds and nothing else but code. Keep in mind the focus of this is purely programming. Then I decided to make a tutorial out of it, so that I can show others some intermediate C# techniques. Hi all, recently I was googling around for some old classic games, and i ran across the old classic Snake game and thought, that would be cool to write in Unity, so I did. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |