hello prospective game developers this is Ikkir I recently went over the first
major UI pass after doing multiplayer input on our game missile comrade and I
realized just how difficult doing multiplayer let alone multiplayer UI
with cursors could actually be therefore I decided to do a miniature
series about getting both basic multiplayer working as well as
multiplier UI in unity during this series I may not end up doing things
that typical unity way as I am more concerned about getting things running
with whatever resources I can muster I will also typically be doing as much
possible in-code and may at times even drop down to lower-level materials in
order to show what is actually going on at any given time my end goal is to show
full project setup all the way to both local and network multiplier action so
let's just get started
first of all to start our set up we will of course need unity itself in this step
I'll be going over all the things we'll be using in this project as well but if
you're already completely set up feel free to skip this part
my current version of unity is 5.6.3f1 with the
current version of Unity at this time is in the 2017 range
feel free to grab the latest version but if you want an older version go to you get
unity slash download slash archive as shown here
follow the directions during the Unity install to completion here you may want
to also select additional modules like WebGL or Android I will most likely be
showing off at the very least some Android and WebGL basics during this
series so please grab them if you want to follow along there while unity is
downloading and installing let's take a look at what else we're going to need
in making our game assets including a lot of UI we will at the very least
need an art program or two we have several options here including paint.net
Aseprite GraphicsGale Gimp Photoshop and more I will be using GIMP
that it is free and I am familiar with it but you can choose what you like
I would also recommend a 3d art tool like 3ds max maya or blender for making
simple models with little that I will do I will be using blender and will go over
the basics of model creation and the asset import pipeline a full blender tutorial
or a 3d art tutorial however are both beyond the scope of this video though so you
may need to look that up on your own
in addition to art I'll be using some very basic sound creation software
called bfxr to create some very simple sound effects
for music I may do some very simple midi creation but more than likely will simply
search for free usable game music as actual music or music creation is also far
beyond the scope of this video with art programs and the audio taken care of
will also need a good way to document our development you can use some sort of
office program if you like but I will be using notepad plus plus here
I will be using some basic version control software and be keeping several
sets of backups you typically always want at least three backups with at least
one of them off-site multiple backups are always necessary as many things can
happen whether it's a fire or laptop being stolen or other such catastrophe
with version control you can use something like SVN or git and I'll be
using git here you can create an online repo for your project on sites like bit
bucket or github as well in addition services like Dropbox or Google Drive
may be useful for backups group collaboration as well from here let's go
ahead and set up our folder and initialize git for our project
have git installed you will see you right click context menus on certain
folders that are allow you easy access to git for repository management here
I'm going to use a simple git GUI to create a new repository in this folder
when this is done you may not see anything in the folder but the
repository is there is just hidden now let's open up unity and start a new
project
from here simply click on new or if you haven't logged in and created a unity account
do that first
I'm going to call my project multiplayer from nothing
and save it
in the folder that I set up
okay what we want to do right now is simple familiarization with the unity
UI over here we have what's called the
scene view this is a look at what exists in your
actual gameplay field which at the start isn't much if anything
you can move this view around by holding down the middle mouse button and
dragging
by holding down the right mouse button and dragging
select objects by left-click or left-click and drag to select
multiple objects change the view from 3d to 2d
select various rendering options for debug purposes
and a few other things that I won't be getting into at this point
below this window we see the game window this window is actually a view of the
scene rendered from a camera in our scene without this camera
we would see nothing just I will show in a moment also in this section we see a
few other options like maximise on play
mute audio stats
and a few others but our most important other thing down here is the resolution
selection
one of the most important things when we do start a new project is figuring out
what resolution we'll be wanting natively
this holds doubly true if you are targeting smartphones or tablets and you
may need to do a little bit of research into how exactly to best setup your
scene then but for our purposes I am just going to leave it as 16:9 for
now
over in this section we see the project folder this shows the files currently
loaded in our project and is our main asset organization point while we are
down here let's go ahead and right-click
create folder
and call it underscore scenes
from there we need to go to the file menu in the top
select/save scene as
and save it as scenes as main
the very basics of unity requires scene creation and saving of such scenes so
it's good to get this part out of the way
after that comes the linked sections where most of
the time and energy in the editor will be spent hierarchy and the inspector
windows whenever you click on an element in the
hierarchy window
you can see information about that object in the inspector window
for example here is our main camera as you see you change the values on the
camera
you can see the gameview change if you turn off the object up here
you can see that the game view reports no cameras there are also other things
attached to the main camera like this audio listener
unity requires exactly one of these in any given scene as these components are
what listen to audio in the scene for things like sounds with 3d falloff
effects I will go over more of the camera stuff later but for now let's
move to game object creation
over in the hierarchy window you can create a new empty game object by
right-clicking and selecting create empty if you right-click an object when you do
this you create an empty game object as a child of that object
I say empty it but it's not quite over in the inspector we see a transform
component every game object has a transform
component that gives a position and placement in the heirarchy
you can see more about these components in the unity reference docs we're going
to be seeing a lot of these docs as nearly everything you need to know about
these components can be found here let's go back to the unity window take a
closer look at the game object we just made
under the game object if you click add component you could see a list of things
we can possibly add right now we are going to add a mesh filter and a mesh
renderer
the mesh filter is what contains the model data of an object mesh and the
renderer determines how it is rendered right now we have no model data so let's
go to the mesh filter and add one
this can be done by clicking on the knob to the right and selecting one of these
defaults that appear in our new select mesh window
let's add a cube
now we can see a cube in our game and scene windows but it appears as purple
because we don't have a material added to the mesh renderer as you can see down
here in materials
you can also use the knob here to select a default material for our Cube
let's select the aptly named default material
now you can see that the look of the cube changed to white
overall there's not much that we can do with the default material though as you
can see in the inspector window we open the information on default
material everything is grayed out we can however create a new material and
add one we can do something with let's do that now back in the project window
let's add a new folder called materials
then inside that folder let's right-click create
new material
let's call this material custom material
now over in the inspector you can see a lot of modifiable values change these
around if you like the preview window will give you an idea of
what your material is going to look like but for now let's just change the color
now if we go back to our new cube press the knob on materials again
we can see our new material in the list of materials to add
we can also simply click and drag from the project window place our new
material and material slot like so
notice though if you click on the material instead of dragging it the
inspector will change that object instead
you can lock the inspector over here by pressing the lock button
or by right-clicking the inspector window and selecting lock
while this pop-up window is open notice the other options here the add tab
option is useful if you wish to change the configuration of your windows as you
can have an additional view the other most notable thing about the
inspector window though is the debug setting
with this setting on you can see a lot more very different information about
the object you have selected most of this won't be immediately useful to you
however but if you're ever wondering why you may be seeing odd things in your
inspector window click to make sure the debug mode isn't selected
anyway back to our cube right now our cube is simply there as a
decoration we go up here and press play
we see that nothing happens let's add another component a rigidbody
lets also make sure our cube is centered to our
game view by going to the gear on the right and selecting reset
now when you press play we see the cube fall down
this is because our rigidbody component has gravity which we can see over here
if we uncheck this checkbox to press play again to gravity no longer applies
let's turn back on gravity and then create something for our cube to interact with
instead of creating an empty gameobject this time I'm going to right-click and
create a premade cube with 3d object cube
notice in the inspector that the pre-made cube is almost like our own
cube except it also has a box collider component and is missing the rigidbody
we added to the other one collider components are what unity calls
into to actually check for object collisions using the inspector let's
move our new cube under our old cube you can either do this manually in the
inspector
by using the move functionality in the scene view
or if you want something quick you can go to the transform on our cube
go to the gear select copy component go to the other
cube click the gear and select base component values then you can trivially
move it under our old cube
now let's press play to see what happens
as you see our cube is still falling but falls right through our cube that supposedly has collision now
that's because we need to add collision of our own to
our cube in order for the object interact from our cube go to add
component box Collider
now we can see the box collider component active on our custom cube if you
change the values of center and size
you can change information about the box Collider
this may be useful if you're using a custom model mesh as well or if your
Collider otherwise does not match the visual of your game object you can also
see a slot for material on this box collider this is not the
same kind of material as what is on the mesh renderer there's another type of
material called a physic material I will go over this more later but for now
let's just press play again to see what happened
as you can see the cube now stops instead of continuing through the other cube
there is however one more value on the box collider the is trigger option
if we press this and press play we notice once again that the cube falls
through the other cube triggers themselves are useful when you want something until
another game object hey you just hit me without actually using the Unity physics
system and moving the other object around now let's go ahead and create a
custom physic material and see if we can make our cube bounce a bit go to assets
folder right click create new folder called physic materials
and then inside it right click create new physic material
let's call our new material cubeBounce over here we can see friction
and bounciness values let's set the bounciness value to one and see what
happens when we go back to our cube
drag the component over to material slot and press play
oops we forgot to take off is trigger
when the cube contacts the other cube now you can see it bounce a little bit
let's go back and edit our physic material a bit change the bounce value to
maximum see what happens
now our cuba is basically acting like a trampoline
watch the cube bounce higher and higher until eventually it will bounce off
if we go back now and set the bounce value to minimum or multiply however you notice the cube does not bounce
at all but simply stops that's because effectively the other cube physic material
has a value of zero since we haven't attached our custom material to it and
either a minimum or multiplication of zero is simply zero by changing bounce
values as well as friction values we can change how our objects interact in our
game with the unity physic system so it's important to remember this for
later
there are also other colliders we can assign to our cubes
which may give different results especially on objects that arent centered
one above one another feel free to experiment further on other colliders
and physic materials to see what happens
now let's go ahead and start with some UI over in the hierarchy right click and
add UI text element as you can see a few things got created
when you do this before we go further make sure you can see your
text on the screen
you can adjust back to 2d view and look at exactly where your text appears on the
screen as well move the text element until its inside or
simply reset its position to 0 X 0 Y for now
now let's look at the canvas itself the canvas is what holds all of the UI
components here we can see several options
the render mode on the canvas chooses just where and how the canvas renders
on overlay mode the canvas renders independent of any of our scene cameras
this is the default mode and most useful for UI in general the screen space
camera mode attaches the canvas to a camera and displays its object in
relation to the camera this can include being behind world objects however so be
careful using this
the worldspace option actually displays the canvas material as if it were a part
of the 3d world so if you move your camera around you can actually see your
UI move as well you might not be able to see it now but the text is inside the UI
world let's say the camera back to overlay
mode move down to canvas scaler the default setting here is constant
pixel size which means that any of your UI will attempt to draw the same amount
of pixels regards to the resolution this also means that if you have a wide range
of supported resolutions if you arent careful your UI could become easily unviewable
the constant physical size on the other hand attempts to make your UI the same
physical size on every screen an inch per inch etcetera for now let's select
scale with screen size and leave the default options in let's go back to our
text object now let's move our text
the top left of the screen here you can move it with the values on the rect
transform which is a special type of transform component for UI
you can also change its anchor position by clicking on the grid box to the left
holding down the Alt key and selecting the top-left option to
move it and set its anchor at the same time
back in our scene view in 2d mode with the text selected we can see the bounds
of the text element in the UI if you adjust the bounds you can see
that the text can become invisible if we shrink it too much
this is because of the options over here under paragraph the text component
wrap causes the text component to fill down when the textbox is too small
while truncate causes any text that goes outside the bounds of the rect transform
to disappear you can also set the overflow mode to
overflow
which means exactly that the text will no longer wrap or truncate in the
direction it's selected
you can also select best fit in order to set the text automatically to fit the
window size
up here there are several font options that you can change as well including the
font itself if you want to change its font download a new font and save it in
your unity project and edit like the materials that we added for on the font
slot one notable thing about text is that
your font may end up blurry at certain sizes and uses in this case what you
want to do is increase your font size
and then downscale the font-size up in the rect transform
depending on the UI that you do you may end up having to do this eventually
on the next episode we will go over scripting in c-sharp and how to actually
change some of these values on our game objects programmatically for now let's
go ahead and save our scene in the file menu
and then let's go back to our git window
if you have closed this window you could reopen it in the same folder you created
it in by right-clicking and selecting git GUI
let's go and hit rescan
once we hit rescan we can see all the changes to our files these are all the
files that we added
to get them ready to save in our git system press stage changed to add in the
commit you may get some warnings at this stage
this is because unity is still open and has temporary files
if so just close unity
and hit rescan then try stage changed once more
later we will go over ways to avoid annoying warnings certain classes of
files some other get GUI systems and also the get bash console once all of
our files are staged let's write in our initial commit message
this can be whatever you like it's best to be descriptive
once you are done here press commit to save the commit to your local git repo
if you have an online repo setup you can use the push option as well to upload
the files there
git itself can be quite complicated so I suggest further reading a lot of
practice to decrease the amount of time you need to mess with git itself on each
commit and to also ensure the integrity of your git repo I would also suggest
reading some more of the unity Docs as well as adding other game objects in
your scene to further familiarize yourself with the unity workflow
that's it for now until next time stay coding
Không có nhận xét nào:
Đăng nhận xét