background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5"

input logo icon
Video tags
|

Video tags

unity
tutorial
games
game development
unity game engine
madewithunity
indiegamedev
indiedev
unity2d
unity3d
tutorials
shield
asteroids
asteroid spawner
shaders
vfx tutorial
unitytutorial
unitytutorialforbeginners
indiegames
cinemachine
animation
vfx
visualeffects
particlesystem
explosions
unityassetstore
asteroidfield
textures
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:01
in this video the fifth in my series on
00:00:04
how to write a 3d space shooter game in
00:00:06
unity we're going to add an asteroid
00:00:08
field spawner and we're going to add a
00:00:11
really cool shield effect that flashes
00:00:13
when it gets hit by weapons
00:00:17
[Music]
00:00:27
okay so when our previous video
00:00:30
we added the asteroid and the ability to
00:00:32
destroy the asteroid
00:00:34
and we have this
00:00:36
rock fracture prefab that corresponds to
00:00:39
that
00:00:40
rock prefab and when we
00:00:43
up and all shoot it
00:00:44
get sent flying and
00:00:46
even hit our ship
00:00:47
so wouldn't it be nice if we spawned an
00:00:50
entire field of asteroids so i'm going
00:00:52
to create an asteroid spawner
00:00:55
i will start by creating an empty game
00:00:56
object i'm going to call it
00:00:59
asteroid field
00:01:04
and go into our scripts folder
00:01:08
and under asteroids
00:01:10
i will create a c-sharp script
00:01:16
and i will call that
00:01:18
asteroid field
00:01:21
and i will select our asteroid field
00:01:23
prefab
00:01:25
wait for unity to rebuild our scripts
00:01:28
and then i will drag that asteroid field
00:01:30
script onto our asteroid field game
00:01:32
object
00:01:33
and while i'm at it
00:01:35
i will drag that into our prefabs folder
00:01:39
in case i ever want to just spawn an
00:01:40
asteroid field
00:01:42
so let's look at that script
00:01:45
let's start
00:01:46
by getting rid of all this
00:01:48
boilerplate code here
00:01:50
and we're going to want some serialized
00:01:52
fields we're going to want to know how
00:01:54
many asteroids to create and i will add
00:01:56
a range
00:01:58
we'll say anywhere between a hundred
00:02:01
and a thousand asteroids this will be an
00:02:04
integer
00:02:05
and we'll just call this asteroid count
00:02:10
and then we're going to want a radius
00:02:12
for our field
00:02:14
so this will also be a range and this
00:02:16
will be a float we'll say anywhere
00:02:18
between say 100
00:02:21
and 500 units
00:02:28
let's get this default values we'll say
00:02:29
we'll create
00:02:31
500 asteroids
00:02:33
and a radius of 300.
00:02:39
and let's see we're going to want
00:02:43
is there any oh we need to prefab a list
00:02:45
of prefabs actually
00:02:46
so let's have a list of game object
00:02:52
and these will be asteroid prefabs
00:02:58
okay
00:03:00
i think that may be all i need for now
00:03:04
but
00:03:05
in the awake method i want to cache my
00:03:07
transform
00:03:14
and
00:03:15
we will create a field called transform
00:03:21
and we're going to want to have a
00:03:25
spawn asteroids
00:03:28
method
00:03:30
and we will call this
00:03:32
from on enable
00:03:38
okay
00:03:40
so in here we're going to
00:03:42
loop
00:03:43
from zero
00:03:47
to our asteroid count
00:03:59
and we are going to
00:04:06
instantiate
00:04:12
asteroid prefabs and we'll do a random
00:04:16
range from xero
00:04:18
to asteroid prefabs
00:04:21
dot count so we'll get a random prefab
00:04:25
and we're going to spawn it at our
00:04:27
transforms position
00:04:30
with quaternion identity for the
00:04:32
rotation
00:04:36
but we're going to want to adjust that
00:04:37
position
00:04:41
to take into account our radius
00:04:44
so we're going to want to have a minimum
00:04:46
rate well
00:04:51
we're just going to use the radius i'm
00:04:52
going to use something called inside
00:04:54
unit sphere so i'm going to say that
00:04:55
asteroid
00:04:57
that transformed that position
00:04:59
plus equals
00:05:01
random inside unit sphere
00:05:04
times radius
00:05:07
and that should position the asteroids
00:05:09
randomly
00:05:11
around
00:05:13
the center point of this asteroid field
00:05:16
within the radius the other thing i want
00:05:18
to do is i want to set their scale
00:05:20
that's what i want
00:05:21
i want to have a serialized field here
00:05:24
so they're not all the same size
00:05:26
how about range
00:05:29
from one to five
00:05:33
um
00:05:34
we'll make that a float
00:05:36
actually you can make it like 0.55
00:05:41
float
00:05:43
scale
00:05:44
and mold
00:05:48
this will be the max
00:05:49
scale
00:06:01
we'll default that to five
00:06:04
so down here we will say that asteroid
00:06:09
dot transform
00:06:10
dot scale
00:06:12
local scale
00:06:14
equals
00:06:15
random
00:06:17
range
00:06:18
we'll go from 0.5
00:06:21
to max scale
00:06:24
oh
00:06:25
actually what i need to do
00:06:47
there we go
00:06:49
all right so that will set its scale
00:06:50
randomly and it's positioned randomly
00:06:52
the other thing i want to do is i want
00:06:54
to apply some torque
00:06:57
so we'll say asteroid dot transform dot
00:07:00
add
00:07:01
a rigid body we need to get the rigid
00:07:03
body
00:07:04
so we will say asteroid dot get
00:07:07
component
00:07:08
rigid body
00:07:11
and if we have one we will add torque
00:07:15
and this will also be a random
00:07:21
inside unit
00:07:24
circle
00:07:28
times random.range
00:07:30
anywhere from zero
00:07:33
to maybe 50.
00:07:36
so that will add some random rotation
00:07:39
in a random direction with a random
00:07:40
amount of force
00:07:43
all right let's see
00:07:44
if that works we will
00:07:47
we have this guy already here he's got
00:07:49
the script attached so we should see
00:07:51
these
00:07:52
parameters
00:07:54
we need to add our prefab so let's go to
00:07:56
asteroids right now we've only got one
00:08:00
to choose from
00:08:02
and let's just hit play see what happens
00:08:10
boom there are our asteroids
00:08:17
it's not a very big asteroid field but
00:08:22
i think that looks pretty cool
00:08:26
start blasting our way through these
00:08:30
cool
00:08:31
all right so they're random size random
00:08:33
rotations of course they're all the same
00:08:35
prefab
00:08:37
um so what we need to do next is start
00:08:39
creating some additional
00:08:41
prefabs
00:08:44
for our asteroids
00:08:47
okay so to create a new
00:08:49
asteroid prefab we're going to go into
00:08:51
our asset store packages to our
00:08:53
breakable asteroids
00:08:56
and we've got all these different
00:08:58
asteroids here that we can use
00:09:01
so let's
00:09:02
bring in
00:09:04
rock two and rock fracture to
00:09:10
and let's look at our prefab here so
00:09:12
we've got
00:09:14
oh i just realized
00:09:16
this script is actually from
00:09:21
the demo from the um
00:09:24
the third party asset pack we don't want
00:09:26
that
00:09:27
uh we're not using that so i will remove
00:09:29
that component
00:09:31
and i will override my
00:09:33
prefab
00:09:35
and so for this one we know we're going
00:09:37
to want to add our own
00:09:39
asteroid script
00:09:41
so let's come into our scripts
00:09:44
asteroids
00:09:46
asteroid
00:09:48
we need to add the prefab for the
00:09:50
fracture so let's go ahead and
00:09:52
do that i know we need this fractured
00:09:54
asteroid script on there
00:09:57
and let me take a look at the other
00:09:59
prefab here
00:10:02
for rock fracture
00:10:04
doesn't look like we added anything else
00:10:07
so this can just be dragged in as a
00:10:09
prefab
00:10:12
and i will delete that from here
00:10:15
go back up to rock 2 and we will drag
00:10:17
that
00:10:18
into our fractured asteroid prefab and
00:10:20
then for the effects we're gonna want
00:10:22
detonator insanity
00:10:25
so that should all be good there we need
00:10:27
to add a rigid body
00:10:29
so let's go up to this guy and we will
00:10:32
say copy component
00:10:34
and then we will add component rigidbody
00:10:39
and then we will paste component values
00:10:42
so that should all be good
00:10:44
i think that maybe all we need to do so
00:10:47
let's drag this
00:10:49
into our prefabs
00:10:54
go into our asteroid field
00:10:56
and here we got rock one let's add rock
00:10:59
two
00:11:03
there we go so now we have rock one and
00:11:06
rock two as the two prefab types if we
00:11:09
hit play we should see
00:11:11
both types of asteroids being spawned
00:11:14
and we do
00:11:16
so you can see that jaggedy looking one
00:11:18
there is rock one and this smoother one
00:11:21
up here is rock two
00:11:25
and it's working okay so we've got two
00:11:27
different types of asteroid prefabs
00:11:30
and we can just repeat that process
00:11:33
for our other prefab types i'm actually
00:11:36
going to pull in the
00:11:37
fractures first
00:11:41
because we're going to have to drag them
00:11:43
in is let me go ahead and delete these
00:11:45
from our
00:11:47
scene
00:11:49
so let's see rock fracture 3 to rock
00:11:52
fracture 15 let's drag them in
00:11:55
we're going to want to select all of
00:11:57
those
00:12:02
and drag that script onto there
00:12:06
and then we're going to go into our
00:12:07
prefab folder
00:12:11
we're going to drag all of them in there
00:12:13
as prefabs
00:12:18
and then we can delete all those
00:12:22
all right let's go back
00:12:24
and drag in rock 3
00:12:28
to rock
00:12:30
15 did i get all
00:12:32
[Music]
00:12:36
15 yes okay i don't know why in my mind
00:12:40
i thought i only got 13.
00:12:42
all right so rock three
00:12:45
to rock 15
00:12:47
drag them into our scene
00:12:51
all right that looks good select all of
00:12:53
them
00:12:54
go to our scripts
00:12:56
and drag asteroid onto them
00:13:00
we're going to want to add a rigid body
00:13:03
and we probably didn't actually do
00:13:04
anything special so i don't need to
00:13:06
copy and paste component values
00:13:09
then we want to drag in the appropriate
00:13:11
fractured asteroids
00:13:13
well first let's go ahead and do the
00:13:15
explosion since they're all going to
00:13:16
have the same explosion
00:13:21
okay
00:13:23
now we have to do these individually
00:13:27
so we want rack fracture three
00:13:45
all right and then all of these will be
00:13:47
dragged into our prefabs folder
00:14:04
and
00:14:05
let's go ahead and delete these from our
00:14:07
scene
00:14:08
go into our asteroid field
00:14:13
we will select rock 3 through rock 15
00:14:18
and we will drag them
00:14:23
let me lock that
00:14:28
we will drag them into our prefabs
00:14:31
so now we've got 15 items
00:14:34
if we hit play we should have 15
00:14:36
different types of asteroids
00:14:45
and the way we can test this is i can
00:14:48
turn off maximize and we can come over
00:14:50
here and look in
00:14:52
the inspector in our hierarchy
00:14:55
and you see we got rock eight rock one
00:14:57
nine we got rocks of all different types
00:14:59
in there and there's our asteroid field
00:15:04
okay so we've got our asteroid field
00:15:06
working
00:15:07
but i want to do something a little bit
00:15:09
different i thought it would be cool
00:15:11
to show you how you can have a shield
00:15:14
on a ship and then when the shield gets
00:15:15
hit it can kind of
00:15:17
flash in opacity and then fade out
00:15:20
so to test this out we'll go into our
00:15:24
hi-res spaceships
00:15:26
and we'll grab a different ship we'll
00:15:28
grab the red one
00:15:29
and pull it out here
00:15:31
and i'm just gonna shove it out in front
00:15:33
of our ship a little bit raise him up a
00:15:35
little bit
00:15:36
uh maybe
00:15:38
rotate him
00:15:40
a little bit
00:15:46
something like that looks pretty cool
00:15:48
and
00:15:49
we're going to want to create a shield
00:15:52
and i want to actually apply a material
00:15:55
to the shield
00:15:56
and i found a material that i think
00:15:58
would be pretty cool in this texture
00:15:59
pack up on hios if you go to hil and you
00:16:02
just search
00:16:04
you can search for materials and you'll
00:16:06
find a bunch of stuff up there and
00:16:07
there's some free stuff and i found this
00:16:10
pack and there's this
00:16:12
kind of
00:16:14
almost like a hexagon type mesh that i
00:16:17
think would look pretty good and you can
00:16:18
go to download now
00:16:20
and if you want to donate you can select
00:16:22
how much you want to donate or you can
00:16:24
just say no thanks take me to the
00:16:25
downloads and if you click download
00:16:27
it'll download this materials underscore
00:16:30
tech dot zip i've already downloaded
00:16:32
that
00:16:33
and if you look in there there's some
00:16:36
several different
00:16:38
types of
00:16:39
meshes and i think i want the
00:16:43
tech grid mesh
00:16:45
and looking at these i think it was
00:16:48
this one
00:16:51
yeah i think i like the looks of this
00:16:53
one so it is a hex
00:16:55
and it's a repeating pattern so it
00:16:57
should wrap around our sphere
00:17:00
nicely
00:17:01
um and then we can just reduce the
00:17:02
opacity on it to make it look kind of
00:17:04
transparent
00:17:06
so i've extracted that into my downloads
00:17:09
folder
00:17:10
if we go into our unity editor
00:17:15
and we go into my materials folder
00:17:19
i'm going to drag
00:17:21
that jpeg image right into there
00:17:25
and so there's there's our jpeg image
00:17:27
now we want to create a material
00:17:30
so i will say create
00:17:35
material
00:17:37
and i want it to be a
00:17:39
transparent
00:17:41
material using the standard shader
00:17:44
and i want to drag this image
00:17:47
onto the albedo
00:17:49
and then i want to give it a little bit
00:17:51
of a
00:17:52
tint
00:17:53
and i want it to be mostly transparent
00:17:58
so i think that looks pretty good
00:18:00
um the other thing i'm going to want to
00:18:02
do
00:18:03
is make it in a mission
00:18:06
and play around with the colors a little
00:18:08
bit here
00:18:16
and so the idea
00:18:18
um
00:18:19
if i was to
00:18:21
add a sphere
00:18:23
so down to 3d object
00:18:25
sphere
00:18:27
and then on our mesh renderer for our
00:18:29
material let's rename this
00:18:33
oops don't want to do that let's rename
00:18:35
that to
00:18:38
shield
00:18:39
material
00:18:43
so we'll pick that
00:18:44
rename this to
00:18:46
shield
00:18:50
and then in our mesh renderer on this
00:18:53
default material we're going to drag our
00:18:54
shield material onto it now you don't
00:18:56
really see anything
00:18:58
so we need to go into the transform for
00:19:00
this guy
00:19:02
and really
00:19:03
bump it up in size
00:19:10
and i want to center that
00:19:13
in our
00:19:14
scene view here
00:19:17
so we can kind of move around and look
00:19:19
at it from different angles
00:19:21
and
00:19:23
if we look at this
00:19:25
value here the intensity
00:19:30
i was envisioning when it gets hit we
00:19:33
could kind of flash that intensity maybe
00:19:35
not that high but up to something like
00:19:37
that and then have it fade down so it
00:19:38
would be kind of like a
00:19:41
uh and we could do the same thing
00:19:43
um
00:19:44
with the regular
00:19:46
opacity here
00:19:48
you know to kind of get that
00:19:50
hex pattern to kind of
00:19:53
flash
00:19:55
and that would all be done via script
00:19:58
but before i do that i really
00:20:01
don't want this to be a perfect
00:20:02
spherical shape i want it to more or
00:20:05
less match the shape
00:20:07
of the ship
00:20:09
so if we come over here and we unlink
00:20:11
these
00:20:12
um
00:20:13
we kind of squish it down
00:20:16
on the y-axis a little bit
00:20:20
kind of move it backwards on the z-axis
00:20:25
let's fly around this guy and
00:20:28
look at him from different angles
00:20:32
yeah that that kind of looks good the
00:20:34
collider did not adjust with it though
00:20:36
it looks like
00:20:40
so let's
00:20:44
take a look at our sphere collider
00:20:49
and we're going to want to oops that's
00:20:51
the position we want to shrink its
00:20:53
radius down
00:20:54
[Music]
00:20:57
and
00:21:00
then i think do i want to use a spear
00:21:04
collider
00:21:07
maybe i want to use a capsule collider
00:21:12
actually you know what i think i want to
00:21:13
use
00:21:14
is a mesh collider
00:21:17
let me remove this
00:21:19
let me add component
00:21:21
mesh collider
00:21:29
yes i think that's a lot better
00:21:33
all right
00:21:35
so we have our
00:21:37
shield
00:21:38
with a collider
00:21:40
and a transparent material
00:21:44
now we just need to add the script so
00:21:46
that we can have it flash when it gets
00:21:48
hit
00:21:50
so let's go to our shield object here
00:21:53
and we're going actually let's go into
00:21:55
our scripts folder
00:21:57
and maybe under ship controls
00:22:01
create a new c sharp script
00:22:05
call it shield
00:22:07
select our shield
00:22:10
drag that on
00:22:13
to our shield component and while i'm in
00:22:16
here
00:22:21
i don't really know if i want to put
00:22:23
that in a subfolder i'm just going to
00:22:24
create a prefab for it
00:22:27
and go into our shield script
00:22:30
get rid of all this boilerplate
00:22:37
and what are we going to want we're
00:22:38
going to want several
00:22:40
serialized fields
00:22:45
um the first one is going to be a color
00:22:48
and that's going to be our flash color
00:22:50
so
00:22:51
by flash i mean when it gets hit i want
00:22:54
to flash it to this color
00:22:57
and then i want to gradually fade it
00:22:58
back to its original color
00:23:01
and we'll default that
00:23:03
to the color white
00:23:05
and
00:23:07
we're going to want to have
00:23:09
a floating point variable i'm going to
00:23:11
make this a range from i don't know
00:23:15
0.25 to 1.
00:23:21
and this is going to be how long it's
00:23:23
going to take to fade out
00:23:26
and we'll default it to half a second
00:23:31
okay
00:23:33
and then we want to have the minimum
00:23:35
intensity
00:23:36
[Music]
00:23:37
remember intensity was the field on the
00:23:39
emission
00:23:40
property
00:23:50
in a max intensity
00:23:53
and i think i wanted that to be zero
00:23:56
because when i was looking at it in the
00:23:57
inspector
00:24:00
it looked like cranking it up to zero
00:24:01
really made that intensity pop
00:24:05
so i think that's all the serialized
00:24:07
fields i need i'm going to want some
00:24:08
private
00:24:09
variables i want our renderer
00:24:11
i need the render
00:24:13
in order to change these colors
00:24:17
um i want to save off our base color our
00:24:20
initial color
00:24:26
and then it's a good idea
00:24:29
when accessing
00:24:32
these
00:24:33
properties the emission properties
00:24:36
on the renderer to cache these guys so
00:24:45
i'm going to want the
00:24:46
[Music]
00:24:49
emission color property and i think i
00:24:52
didn't want that plus sign to be in
00:24:53
there
00:24:55
and that's just for performance reasons
00:24:58
so in the awake method
00:25:02
i need to grab my renderer
00:25:12
and i need to make sure i spell it
00:25:14
correctly
00:25:17
and i want to save off our base color
00:25:28
okay and we're going to want to
00:25:30
implement the eye damageable interface
00:25:39
so we're going to take damage
00:25:42
and ultimately i think when we
00:25:45
we're going to want to have
00:25:46
a certain number of hit points
00:25:50
for lack of a better word that this
00:25:53
shield can take before it's destroyed
00:25:55
and we'll probably want to make that a
00:25:56
serialized field
00:25:58
but for now i just want to work on the
00:26:00
visuals i want to see that when we take
00:26:02
damage
00:26:03
that we flash
00:26:05
and i'm going to do this in a co routine
00:26:07
i'm going to create a co routine i
00:26:10
enumerable
00:26:11
no i enumerator
00:26:16
flash and
00:26:18
fade
00:26:19
shields
00:26:23
and so in here
00:26:25
i'm going to say start
00:26:27
co-routine
00:26:30
flash and fade shields
00:26:32
so whenever we take damage we're going
00:26:34
to flash and fade shields
00:26:37
and this is where the magic is going to
00:26:39
happen
00:26:42
so we're going to want some variables
00:26:43
here we're going to want a
00:26:46
shield color
00:26:47
variable
00:26:50
and then we're going to want to grab the
00:26:51
current emission color
00:26:56
we're going to get that off our renderer
00:27:00
material get color
00:27:07
and we'll use that cached
00:27:09
property id
00:27:11
that we got here
00:27:14
all right
00:27:16
um
00:27:17
what else do we need we're going to want
00:27:19
to start our
00:27:20
counter
00:27:22
so let's say current time
00:27:29
current
00:27:30
time
00:27:36
we're going to set the intensity
00:27:39
to be our max intensity
00:27:45
and while
00:27:47
current time
00:27:49
is less than
00:27:51
fade out time
00:27:58
and then just to make sure that we
00:27:59
actually will eventually break out of
00:28:01
this loop i'm going to say current time
00:28:03
plus equals
00:28:05
time dot delta time
00:28:07
and then we're going to yield
00:28:09
return
00:28:10
null
00:28:12
and at the end of this function we're
00:28:13
going to yield
00:28:17
break
00:28:19
okay so
00:28:23
while we're fading out
00:28:29
let's see what we want to do here we
00:28:31
want to say the shield color
00:28:37
is going to we're going to use the alert
00:28:39
function we're going to learn
00:28:41
from our flash color which is the
00:28:43
brightest flash color that we want down
00:28:46
to our base color
00:28:49
and we're going to learn over current
00:28:51
time
00:28:52
divided by
00:28:54
our fade out time so this should do it
00:28:56
smoothly over that
00:28:58
whatever this fade out time is
00:29:02
and we want to also alert the intensity
00:29:04
[Music]
00:29:06
so say intensity equals math f dot lerp
00:29:12
we want to go from our max intensity
00:29:15
down to our min intensity
00:29:19
and we want to do the same current time
00:29:21
divided by
00:29:22
fade out time
00:29:26
so now
00:29:28
we're going to want to create a new
00:29:29
function i'm going to call it change
00:29:32
shield
00:29:35
color
00:29:36
we're going to pass in
00:29:38
our shield color
00:29:46
and we're going to pass in our
00:29:49
emission color
00:29:54
times
00:29:59
this is um
00:30:01
just a little something that you need to
00:30:02
do
00:30:04
to
00:30:05
make sure that the intensity is applied
00:30:07
correctly i don't really understand why
00:30:10
but it's a way that they represent the
00:30:13
intensity value you have to
00:30:16
do this little equation here
00:30:19
oops
00:30:21
i was trying to
00:30:23
huh
00:30:27
is it alt enter oh i'll enter okay
00:30:29
create method
00:30:32
shield color emission color what do we
00:30:34
want to do in here
00:30:35
we want to grab our renderer's material
00:30:38
color and set it
00:30:40
to color
00:30:43
shield color
00:30:47
okay
00:30:48
and then we want to set the material
00:30:53
emissions color
00:30:58
to be emission
00:31:00
color
00:31:03
that
00:31:04
should do it if i didn't make any
00:31:06
mistakes
00:31:10
so what do we want
00:31:12
to put in those values
00:31:16
i think
00:31:19
well if we go into the material
00:31:27
i think i want to copy that color
00:31:37
huh
00:31:39
well but let me
00:31:40
paste that let me just do that and then
00:31:43
i'll crank the opacity
00:31:45
down a tad probably
00:31:48
maybe about 50
00:31:53
and maybe make this a little bit
00:31:54
brighter
00:31:58
okay and then for fade out time
00:32:01
half a second should be fine
00:32:08
let's see how those values look
00:32:11
i'm going to turn off our asteroid field
00:32:15
hit play
00:32:18
let me
00:32:24
that's pretty cool
00:32:28
let me uh crank up that intensity a
00:32:30
little bit
00:32:45
oh yeah
00:32:49
i think that looks really cool
00:32:52
um i think i probably want to have our
00:32:54
projectile spawn a little
00:33:00
explosion where it hits though
00:33:03
and i think our projectile is continuing
00:33:06
on even after it hits so we want to make
00:33:08
sure the projectile is destroyed when it
00:33:10
hits something
00:33:14
so
00:33:15
let's go into our projectile
00:33:20
weapons
00:33:24
yeah it does not have any kind of an
00:33:26
explosion
00:33:29
so let's add a serialized field
00:33:33
and we'll say
00:33:36
detonator because we'll use a detonator
00:33:41
um
00:33:42
hit effect
00:33:46
and so
00:33:47
in on collision enter
00:33:52
we can say
00:33:54
if
00:33:56
hit effect is not equal to null
00:34:00
instantiate
00:34:03
hit effect
00:34:05
transform that position
00:34:09
um quaternion identity
00:34:16
and
00:34:17
we also want to make sure that we
00:34:19
destroy
00:34:21
game object
00:34:26
okay if we go back into the unity editor
00:34:32
select our projectile prefab
00:34:41
and let's see under effects
00:34:43
tiny
00:34:47
okay
00:34:49
hit play
00:34:58
i'm not seeing that
00:35:01
oh i am seeing it it's just very
00:35:04
very hard to see up against the shield
00:35:08
oh that that's nice
00:35:13
okay
00:35:14
awesome so there you go we've got an
00:35:18
asteroid field
00:35:19
i'm gonna go ahead and turn that back on
00:35:25
i can fly around our asteroid field
00:35:32
all right so we've got asteroids
00:35:35
we've got an enemy ship with shields
00:35:40
that flash one hit
00:36:02
actually i think one more thing i'd like
00:36:04
to do before i wrap this video up
00:36:07
i'm noticing those shields look awfully
00:36:10
opaque
00:36:12
so i want to go into the
00:36:15
material
00:36:20
and maybe reduce it down even more
00:36:28
by default
00:36:30
so hit play
00:36:36
yeah that looks a little bit better
00:36:43
i've noticed that our rocks are falling
00:36:52
yes they are falling so i wonder why we
00:36:54
didn't see that before the um prefab for
00:36:57
the asteroids all the new asteroids
00:37:00
that i created
00:37:03
their
00:37:06
um their rigid body must have gravity
00:37:09
enabled
00:37:12
yes use gravity is enabled
00:37:15
so let me hit play
00:37:21
that's better i wonder why they weren't
00:37:23
falling before though
00:37:33
well that about wraps it up for this
00:37:35
video if you liked what you saw and
00:37:37
found it useful do me a favor click that
00:37:38
like and subscribe button and if you
00:37:41
have any questions or comments or maybe
00:37:43
a suggestion about what you'd like to
00:37:44
see me cover in future videos drop a
00:37:46
comment below and i'll get back to you
00:37:48
as soon as i can on that thanks again
00:37:50
for watching and good luck on your game
00:37:52
development journey
00:37:55
[Music]

Description:

Step-by-step Unity tutorial for beginners where you will learn how to make a 3D Space Shooter in Unity. In this installment we add an asteroid field spawner and some cool shield effects. Link to entire playlist for this tutorial series https://www.youtube.com/playlist?list=PLHcOLPSLOK7PNvLAdnqicE_BeqoNH7Zwz 00:00 - Intro 00:30 - Adding asteroid spawner 08:40 - Added second asteroid prefab 11:30 - Create prefabs for all the other asteroid types 15:50 - Create shield component 33:00 - Tweak projectile, add hit effect and destroy it when it collides with something 36:45 - Fix "falling" asteroids 37:30 - Outro Texture Pack from itch.io: https://juliovii.itch.io/techpk01 Source code on GitHub: https://github.com/gbradburn/3D-Space-Shooter-Tutorial/tree/AsteroidField My Links: My website: https://midniteoilsoftware.com/ My itch.io site: https://midniteoilsoftware.itch.io/ Twitter: https://twitter.com/SoftwareOil https://discord.com/invite/wrdqXPtw9y https://www.facebook.com/unsupportedbrowser

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "How to Make a 3D Space Shooter Game in Unity - Tutorial Part 5"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.