Chapter 10. Gameplay Scripting

We've come a long way in the past few chapters and have created a great deal of our game, but we still need to do a bit of work to implement some of our gameplay concepts. In this chapter we'll explore some of the gameplay scripts needed to implement the play mechanics of our game.

In this chapter we shall learn:

  • How to add a particle system to our imported models to simulate a weapon
  • How to use animation to drive events in the game
  • How to handle ragdoll physics on our character and enemies
  • How to keep score and trigger events based on gameplay

With these basics we'll have the core of an actual game's play mechanics completed and all we'll need to do is add this to the world the characters live in.

Gunplay as gameplay

As our game is a shooter, one of the primary gameplay mechanics we need to provide is a mechanism through which guns can fire projectiles and hit other objects in the world. While there are many ways to accomplish gunfire in the game such as simulating the gunfire or creating game objects that represent projectiles, the more efficient mechanism to represent gunfire is a particle system. By attaching a particle system to our gun object, we can easily draw a representation of projectiles being fired at objects in the game world.

Particle Systems in Unity support physics, collision, and memory management in a way that is particularly efficient for mobile devices. The only issue to watch for is that the fill rate (the rate at which the screen can be filled or drawn) for mobile devices is not as high as that of their desktop cousins. Similarly, if you perform actions such that the engine must redraw certain areas of the screen repetitively, you will see the same fill-rate issues. So if you have a lot of particles that are taking up large sections of the screen, you will likely have a performance issue. We will discuss this in much greater detail during the optimization chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.113.197