O'Reilly logo

Introduction to Game Design, Prototyping, and Development: From Concept to Playable Game with Unity and C#, 2nd Edition by Jeremy Gibson Bond

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 22

LOOPS

Computer programs are usually designed to do the same thing repeatedly. In a standard game loop, the game draws a frame to the screen, takes input from the player, considers that input, and then draws the next frame, repeating this behavior at least 30 times every second.

A loop in C# code causes the computer to repeat a certain behavior several times. This could be anything from looping over every enemy in the scene and considering the AI of each to looping over all the physics objects in a scene and checking for collisions. By the end of this chapter, you'll understand all you need to know about loops, and in the next chapter, you'll learn how to use them with various C# collections.

Types of Loops

C# has only four kinds of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required