From the course: Unity 5: Network Gaming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Firing projectiles

Firing projectiles - Unity Tutorial

From the course: Unity 5: Network Gaming

Start my 1-month free trial

Firing projectiles

- [Instructor] We've got our Shot Prefab setup so next we'll modify our tank controller script to detect whether or not the players press the spacebar. And if they have, we'll go ahead and instantiate a new shot. For this I need to open up the tank controller script so I'll just find it here on my tank, double click it to open it in my code editor. The first thing I'll modify is at the top of the class. I'll go ahead and put a public game object field in here to hold my Shot Prefab. (typing) And next I'll go ahead and put a spot to hold the Transform where we're going to instantiate. (typing) And I'll call that ShotSpawnTransform. Finally, I know I'm going to need some sort of variable for shot speed so I'll go ahead and make a float for that. (typing) With those public variables defined, let's go down into our update method and now the code that actually detects whether or not the player has pressed the spacebar. I'm going to add this down at the bottom of the method so far, and I'll…

Contents