ME FIRST GAMES
Menu
games for me and you
The "if else" conditional statement allows you to change the flow of your program.
For game devs, "if else" is essential to implement the features of your game. 📌 You'll use the "if" statement to determine if the player is dead, jumping, swimming, attacking, and much more. 📌 You can put any conditional in your "if" statement as long as it evaluates to true or false. 📌 You can use the logical AND operator "&&" to return true if both sides are true. 📌 Use the Logical OR operator "||" to return if either side is true. 📌 The Logical NOT operator "!" may be used to reverse the outcome of an expression. 📌 It's possible to chain many expressions using these operators, but good practice is to define a method for large conditional statements. 📌 If you are a beginner and struggling to grasp the "if else" statement, then no sweat. 📌 "If else" is a basic construct, a building block used in all programs and games. 🚀 if ( YouHaveWillToLearn() ) // then the "if else" concept will soon click. ➡️ Follow @mefirstgames for more game dev tips. ➡️ Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html
0 Comments
The Control Flow of a program is the order in which the program's code executes. As a competent programmer, you NEED to understand where you are in the Control Flow and where it can lead you. 📌 By default, your program will execute instructions in a linear order, executing each line of code after the next. 📌 This linear flow can be broken up using conditional statements and function calls. 📌 It's easy to represent the Control Flow of your program using a graph. 📌 If using GCC, you can use tools like Trucov to print the Control Flow of your program. 📌 The If-Statement and Switch-Statement will cause your Control Flow to branch. 📌 Loops will cause your Control Flow to go back to a previous node. 📌 Function calls will jump to an entirely separate part of your control flow. ✅ When you are writing lines of code, you are defining the Control Flow of your program. ✅ Where it can branch, loop, jump, break; essentially what it can do and where it can go. ✅ The cool thing about the Control Flow is that you don't have to understand the entire graph at once. ✅ The graph can be broken up or "encapsulated" into a single section. ✅ This makes it easier for us to understand; that's why we separate code into different functions and classes. 🎮 In Unity, you can think of the entire Control Flow as a huge massive graph. 🎮 But we only need to worry about the Control Flow in our own MonoBehaviors. ➡️ Follow @mefirstgames for more game dev tips. ➡️ Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html The Singleton design pattern keeps the instantiation of a class to a single instance. Controversial but convenient, Singletons are something you will most definitely encounter in your life as a developer. 👍Singletons are very quick to implement and can make accessing an object easy. 👍Better than static classes, they can leverage polymorphism, cache values, and have their instances swapped out. 👍They require low memory usage, low latency, and only need one initialization. 👍In Unity, it offers better performance then FindObjectOfType. 👎Controlling initialization order across Singletons can become messy very quickly. 👎Deviates from the single responsibility principle. 👎Promotes mass coupling to a single instance. 👎It can be difficult to refactor, especially if you need to change its behavior in a different context. 👎In Unity, it is difficult to track the lifecycle of the Singleton MonoBehavior. 👎It's not always easy to subclass and extend. 👎Easy to abuse with many singletons and have limited flexibility in your codebase. ✅Do I recommend Singletons? Well, it depends... ✅Is your project small? Do you have time constraints? Will your class change in the future, or will it most likely always behave the same? e.g. logging system. ✅Singletons are not the cleanest or most flexible system, but they are convenient and quick to implement. ✅In Unity, Singleton MonoBehaviors can swap instances depending on what scene or prefab is loaded. 🚀Beware overuse, understand the limitations, and use it at your own discretion. ➡️Follow @mefirstgames for more game dev tips. ➡️Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html |
Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
Red MatterStar Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.
Archives
April 2021
Categories |
Copyright (c) 2020 Me First LLC
|