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 - Unity Tutorial
From the course: Unity 5: Network Gaming
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Project overview3m 15s
-
(Locked)
Set up the Network Manager2m 11s
-
(Locked)
Network identity3m 1s
-
(Locked)
Testing the game3m 46s
-
(Locked)
Network transform6m 58s
-
(Locked)
The local player6m 26s
-
(Locked)
Instantiate projectiles6m 58s
-
(Locked)
Firing projectiles6m 5s
-
(Locked)
Multplayer projectiles5m 2s
-
(Locked)
Adding a health indicator, part 12m 53s
-
(Locked)
Adding a health indicator, part 23m 44s
-
(Locked)
Adding a health indicator, part 34m 46s
-
(Locked)
Multiplayer health5m 54s
-
(Locked)
Fragging the enemy5m
-
(Locked)
Respawning6m 14s
-
(Locked)
-