Rezumat în limba română … … … … 5 [623922]
1
Contents
List of figures ………………………….. ………………………….. ………………………….. ………………………….. 3
Rezumat în limba română ………………………….. ………………………….. ………………………….. …………. 5
1. Stadiu actual ………………………….. ………………………….. ………………………….. …………………….. 5
2. Fundamentare te oretică ………………………….. ………………………….. ………………………….. ……… 5
3. Implementare ………………………….. ………………………….. ………………………….. ……………………. 7
4. Rezultate experimentale ………………………….. ………………………….. ………………………….. …….. 8
5. Concluzie ………………………….. ………………………….. ………………………….. …………………………. 9
Work planning ………………………….. ………………………….. ………………………….. ………………………. 10
1. State of the Art ………………………….. ………………………….. ………………………….. ………………… 11
1.1. What is a video game ………………………….. ………………………….. ………………………….. ……. 11
1.2. Games genres ………………………….. ………………………….. ………………………….. ………………. 11
1.2.1. Depending on the platform ………………………….. ………………………….. …………………… 11
1.2.2. Depending on the purpose of the game ………………………….. ………………………….. ….. 11
1.2.3. Depending on gameplay ………………………….. ………………………….. ………………….. 12
2. Theoretical Fundamentals ………………………….. ………………………….. ………………………….. …. 14
2.1 Hardware ………………………….. ………………………….. ………………………….. ……………………… 14
2.2 Software ………………………….. ………………………….. ………………………….. ………………………. 14
3.Implementation ………………………….. ………………………….. ………………………….. …………………… 17
3.1 Downloading the required programs and creating a new project ………………………….. …… 17
3.2 Creating the terrain ………………………….. ………………………….. ………………………….. ………… 17
3.2.1 Sculpting the terrain ………………………….. ………………………….. ………………………….. …. 17
3.2.2 Painting the terrain ………………………….. ………………………….. ………………………….. …… 19
3.2.3 Trees grass and buildings ………………………….. ………………………….. ……………………… 20
3.3 Creating the player ………………………….. ………………………….. ………………………….. ………… 23
3.3.1 Creating and positioning ………………………….. ………………………….. ……………………….. 23
3.3.2 Character controller ………………………….. ………………………….. ………………………….. …. 23
3.3.3 Camera ………………………….. ………………………….. ………………………….. …………………… 23
3.3.4 Positioning the weapons ………………………….. ………………………….. ……………………….. 23
3.3.5 Player’s movement ………………………….. ………………………….. ………………………….. ….. 25
3.3.6 Mouse look and mouse controls ………………………….. ………………………….. …………….. 26
3.3.7 Player’s Sprint and Crouch ………………………….. ………………………….. ……………………. 26
3.3.8 Player’s Footsteps Sound ………………………….. ………………………….. ………………………. 27
3.3.9 Animating Hands and Weapons ………………………….. ………………………….. …………….. 28
3.3.10 Weapon Handler ………………………….. ………………………….. ………………………….. ……. 30
3.3.11 Weapo n Manager ………………………….. ………………………….. ………………………….. …… 31
3.3.12 Player Attack ………………………….. ………………………….. ………………………….. ………… 31
3.3.13 Creating the Zoom Effect with animations ………………………….. …………………………. 33
2
3.3.14 Creating arrow and spear bullet ………………………….. ………………………….. ……………. 34
3.3.15 Configuring and animating the cannibal enemy and creating the enemy animation
script ………………………….. ………………………….. ………………………….. ………………………….. …. 35
3.3.16 Enemy Controller ………………………….. ………………………….. ………………………….. ….. 37
3.3.17 Detecting and dealing damage ………………………….. ………………………….. ……………… 39
3.3.18 Creating the Health Script ………………………….. ………………………….. …………………… 43
3.3.19 Creating Player and Enemies sound effects and shoot effects sounds ………………… 43
3.3.20 Creating the User Interface and Menu ………………………….. ………………………….. …… 44
4. Experimental Results ………………………….. ………………………….. ………………………….. ………….. 47
4.1 Main menu ………………………….. ………………………….. ………………………….. ……………………. 47
4.2 Gameplay ………………………….. ………………………….. ………………………….. …………………….. 48
5. Conclusions ………………………….. ………………………….. ………………………….. ……………………….. 52
6.References ………………………….. ………………………….. ………………………….. ………………………….. 53
7.Appendix ………………………….. ………………………….. ………………………….. ………………………….. .. 54
3
List of figures
Figure 1. Terrain Tools.
Figure 2. Terrain Settings.
Figure 3. Terrain Sculpting
Figure 4. Terrain Texture and Layers.
Figure 5. Winter Forest Pack.
Figure 6. Winter Forest Pack.
Figure 7. Terrain Trees.
Figure 8. Positioning Buildings.
Figure 9. Positioning Buildings
Figure 10. Character Controller
Figure 11. Weapon/Enemy Material
Figure 12. Adding Weapons.
Figure 13. Positioning Weapons.
Figure 14. Plyer Movement Script.
Figure 15. Mouse Look Script.
Figure 16 Player Sprint and Crouch Script.
Figure 17 Player Audio Object
Figure 18 Plyer Footsteps Script
Figure 19 Weapon Animations.
Figure 20 Linking Animation Controller.
Figure 21 Animation States.
Figure 22 Animation State.
Figure 23 Configurating Weapon Animator.
Figure 24 Configurating Bow and Arrow Animator
Figure 25 Weapon Handler Script
Figure 26 Attaching the Weapons to the Script
Figure 27 “Transition Duration” and the “Transition Offset” off.
Figure 28 Configuring Idle/Attack States.
Figure 29 Linking the FP camera Controller
Figure 30 Creating Zoom Animation.
Figure 31 Configuring Zoom Animation.
Figure 32 Unchecking the Loop Time.
Figure 33 Bow and S pear Model.
Figure 34 Player Attack Script.
Figure 35 Arrow Bow Script.
Figure 36 Enemy Model.
Figure 37 Configuring the Enemy Box Collider.
Figure 38 Configuring the Enemy Animator.
Figure 39 Enemy Animations.
Figure 40 Navigation Tab.
Figure 41 Walkable Areas.
Figure 42. Creating Attack Point.
Figure 43 Attack Point Script
Figure 44 Attack Point Event.
Figure 45 Attack Point ON
Figure 46 Attack Point OFF
Figure 47 Enemy Attack Point.
Figure 48.Attack Point OFF.
Figure 49 Health Script.
Figure 50. “PlayWooshSound” Event.
4
Figure 51. Enemy Audio Script.
Figure 52 Crosshair.
Figure 53 Health and Sprint Bar.
Figure 54 Main Menu
Figur e 55. Game Folder.
Figure 56. Main Menu.
Figure 57. First Person.
Figure 58. Weapons.
Figure 59 Enemy.
Figure 60. Dead Enemy
Figure 61. Bow Bullet.
Figure 62. Weapon Shooting.
Figure 63. Respawning after being killed.
5
Rezumat în limba română
1. Stadiu actual
Un joc video este un joc electronic care interacționează cu o interfață grafică pentru a
genera un semnal vizual pe un ecran. Jocurile video au de obicei un sistem de recompensare a
utilizatorului, de cele mai multe ori scorul este păstrat, acest sistem depinzând de realizarea unor
obiective din joc.
Jucați jocuri video este o modalitate de a vă relaxa și a uita de problemele din viața dvs.,
intrând într -o lume cu totul nouă, unde puteți face orice doriți fără consecințe. În această lume
veți fi o persoană diferită, fără responsabilități.
Jocurile video pot fi clasificate după mai multe crite rii ținând cont de platformă, ținând cont
de scopul jocului sau de joc în sine. După joc în sine acestea pot fi clasificate în :
Acțiune
platformer
fighter & beat em up
de Aventura
shooter și în multe altele
Eu mă voi axa pe jocurile de acțiune, mai pr ecis cele de tip shooter.
Shooter elefant.to este a doua subcategorie a genului de jocuri de acțiune. În aceste jocuri
utilizatorul folosește arme ca să doboare inamicii. Majoritatea shooter -elor implică un joc violent,
sânge și război.
Titlurile Call of D uty, Halo și Far Cry sunt cele mai relevante exemple pentru acest gen și
asta pentru că reușesc să combine o varietate impresionantă de arme și un univers imens populat
de tot felul de obiecte dinamice. În funcție de perspectiva din care se desfășoară jocu l, shooter
ele sunt la rândul lor împărțite în două categorii: shooters la prima persoană care te pun direct în
pielea personajului și văd practic ceea ce vede și shootere la persoana a treia, în care personajul
este urmărit de în spate, care oferă jucător ului un câmp vizual mai larg și un control mai bun
asupra mediului
Jocurile de supraviețuire sunt un subgen al jocurilor video de acțiune. Jocurile sunt
amplasate în medii ostile, intense, cu lume deschisă. Jucătorii sunt echipați cu echipamente
minime și trebuie să supraviețuiască mediului dur cât pot de mult.
2. Fundamentare teoretică
Am ales această temă pentru că am fost mereu preocupat de jocurile pe computer.
Printre avantajele utilizării jocurilor se numără:
1. Au un efect terapeutic pentru copiii cu boli cronice
2. Preșcolarii își dezvoltă mai bine abilitățile motorii
3. Jocurile video reduc stresul și depresia
4. Ameliorează durerea
5. Păstrează -mi inima sănătoasă
6. Îmbunătățesc vederea și mențin creierul angajat
7. Îmbunătățiți abilitățile de luar e a deciziilor ă[2]
6
Acest joc este conceput pentru a fi jucat pe computer. Mai întâi să învățăm puțin despre
platforma pe care vom crea jocul.
La mijlocul anilor 1970, a apărut o nouă tehnologie: miniprocesorul. El a folosit mulți tranzistori
conectați la un cip de siliciu pentru a face un dispozitiv de calcul.
Primii microprocesoare erau, conform standardelor actuale, destul de simple. Primul
microprocesor a devenit cunoscut sub numele de 4004, de la Intel. Microprocesoarele au fost
inițial utilizate ca co ntroler – dispozitive de control – pentru mașini de spălat vase și frigider.
Producătorii și designerii de computere nu au ratat ocazia ca aceste dispozitive să fie utilizate ca
computere.Primul produs de succes a fost microprocesorul Intel 8080 și noul si stem de operare
numit CP / M -80.Astăzi avem Intel și AMD care domină piața procesoarelor, creând procesoare
octa core multithreaded care sunt accesibile pentru aproape toată lumea. Acum, memoria RAM
medie pe care o are un PC este de 4 GB, care a fost consi derată „excesivă” acum 15 ani. Prin
„suprasolicitare” vreau să spun că este mai mult decât suficient RAM (sistemul nu va folosi
niciodată toată memoria). Producătorii de GPU -uri, care sunt NVIDIA și AMD RADEON,
lansează plăci video care au o memorie video de 8GB, care sunt accesibile. Acest lucru a fost de
neimaginat în 2005.
Putem spune în siguranță că tehnologia a evoluat rapid și că aplicațiile s -au dezvoltat în
consecință.
Unity 3D este cel mai popular motor de joc [3 ] dezvoltat de Unity Technologies pe ntru a
crea conținut nu numai pentru un singur tip de platformă, ci pentru mai mult de 25 de platforme
diferite, inclusiv desktop, console, mobile și realitate virtuală, făcându -l un motor de joc
multiplataforma cu caracteristici nevalorizate.
Unele dintre platformele pentru care Unity poate construi aplicații sunt Oculus Rift, Google
Cardboard, Steam VR, PlayStation VR, Gear VR, Windows Mixed Reality, Daydream, Android
TV, Samsung Smart TV, TV OS, Nintendo Switch, Vuforia, iOS, Android , Windows, Universal
Windows Platform, Mac, Linux, WebGL, PlayStation 4, PlayStation Vita și Xbox One. De cele
mai multe ori, motorul este folosit pentru a dezvolta jocuri bidimensionale și tridimensionale,
aplicații de realitate virtuală și realitate augmentată, dar și o mul țime de alte simulari și experiențe
unice. [4 ]
Datorită faptului că are o mulțime de instrumente profesionale benefice atât pentru un
dezvoltator, cât și pentru un artist (de exemplu, prin instrumente puternice de animație) Unity a
atras atenția nu numai d ezvoltatorilor de jocuri, ci și altor industrii din afara jocurilor video.
precum: arhitectură, inginerie și construcții, industria cinematografică și auto.
În lumea ingineriei, Unity este un instrument care permite ca multe idei inovatoare să fie
aduse l a viață printr -un mediu de dezvoltare în timp real. Când vine vorba de filme, animații și
divertisment vizual, Unity oferă un număr nelimitat de oportunități. Prin intermediul acestei
platforme, puteți crea seriale TV, filme de lung metraj, dar și scurtmet raje CGI, toate în înaltă
definiție și cu un grad ridicat de detalii.
Limbajul de programare C # este utilizat pentru a conecta scripturi în Unity. C # este printre
cele mai utilizate limbaje de programare din lume. Este un limbaj simplu, modern, cu o mare
flexibilitate în ceea ce privește dezvoltarea aplicației și portabilitatea. Printre principalele calități
ale limbajului, putem distinge: modernitate, simplitate, utilitate generală, productivitate ridicată,
stabilitate în aplicații complexe, durabilitate , este un limbaj total orientat obiect (orice entitate
din acest limbaj este de fapt un obiect), oferă suport complet pentru dezvoltarea componentelor
necesare în medii distribuite, deci este, de asemenea, un limbaj de programare orientat pe
componente.
7
3. Implementare
La implementare primul lucru care trebuia să -l facem a fost să descărca în programele
necesare și anume Unity și Visual Studio. Următorul pas a fost este să descărcăm “Terrain Tools
Sample Asset Pack” cu ajutorul căruia putem să creăm harta noastră. După aceea descărcăm
“Winter Forest – Low Poly Toon Battle Arena / Tower Defense Pack” care ne oferă modele și
animatii pentru clădiri și vegetație.
După ce am rezolvat cu vegetația este timpul să creăm clerul nostru care trebuie să conțină
un “ch aracter controller”, “rigid body și “boxcollider” pentru a fi un obiect fizic. Este momentul
să blocăm camera ca să stea în perspectiva player ului. Odată cu camera poziționată
corespunzător trebuie să pozitionam armele ca să se vadă cum trebuie în cameră după care vom
adăuga o textură pe ele.
Este timpul să creăm scriptul care îi da posibilitatea player ului de a se mișca și scriptul
care blochează camera în funcție de coordonatele mouse -ului (scriptul care ne lasă sa ne rotim
cu mouse -ul). Următorul pas este să creăm scriptul care internit a player ului să alergie în mod
Sprint și în să meargă mod Crouch după care vom atașa sunetele de pași pentru Player. În acest
moment ne rămâne de animal mâinile și armele playerului pe care le vom face cu ajutorul
anim atorului.Următorul pas este de a crea scriptul “Weapon Handler” care va face diferența
dintre arme.
De exemplu nu vom putea să tragem gloanțe cu un topor sau să lovim un inamic cu pistolul.
”Weapon Manager” este scriptul care va fi creat. Acesta ne da abi litatea de a selecta armă dorită
folosind tastele de la 1 la 6. Este timpul să creăm “Player Attack” care controlează tragerea cu
arma selectata. Dacă putem să tragem cu arma va trebui să putem și să țintim cu ea așa că vom
crea efectul de Zoom cu animație . Având în vedere că nu toate armele trag cu gloanțe, de exemplu
Sulița și arcul nu trag gloanțe, va trebui să creăm modelele “arrow” și “spear”.
Acum că putem să tragem cu caracterul va trebui să avem și un amic în care să putem trage,
deci următorul pas este să configuram și să animam inamicul nostru canibal.După ce am
configurat va trebui să creăm scriptul “Enemy Controller” Pentru ca acesta să aibă abilitatea de
a se mișca de bunăvoie pe hartă și să ne atace în cazul în care noi ne apropiem de el.
Acum că am reușit ca inamicul să ne atace este timpul să detectăm și să dăm lovituri
inamicului, facem asta prin crearea scriptului “Attack Script”. A sosit momentul în care vom
crea “Health Script” script. Acesta are rolul de a aloca jucătorului și inamicului o valoare
(100) care dacă ajunge la zero, inamicul sau jucătorul va muri.
Trece timpul să facem retușurile finale prin adăugarea sunetelor pentru inamici și pentru
arme. După ce Jocul este funcțional va trebui să creăm și un “user interface” (UI). Pentru UI vom
face bara de viață și de sprint și de asemenea vom face și un meniu cu două butoane de unde pot
să ies din joc sau să începi jocul.
8
4. Rezultate experimentale
După ce lansăm jocul, primul lucru care ne întâmpină este meniul principal. Aici observăm
că cele două butoane principale, „Play” și „Quit” funcționează corect.
Dacă apăsăm „Quit”, părăsim jocul, dacă apăsăm „Play”, vom trece la faza următoare, care
începe aventura noastră de supraviețuire.
Odată ce apăsăm butonul „Play”, ne află m în locul de reproducere al jucătorului.
Primul lucru pe care îl vom vedea este mediul, adică am creat cu succes terenul cu toate
componentele sale (vegetație și clădiri). Următorul obiect pe care îl vom observa este că arma
este securea care este arma # 1deci știm că scriptul „Weapon Handler” funcționează. De
asemenea, toporul este aliniat corect.
În următoarea captură de ecran putem observa că bara de sprint și -a redus valoarea,
deoarece fugeam de inamic indicând faptul că ne putem deplasa cu personajul și, de asemenea,
să mutăm vizualizarea camerei cu mouse -ul. De asemenea, în această imagine, țineam butonul
de clic dreapta, așa că țintea sulița spre inamic.
Observăm că putem vedea că inamicul stă într -o locație goală, ceea ce înseamnă că este un
loc d e mers pe jos. Știind acest lucru, putem presupune că funcția de „patrulare” a inamicului
funcționează bine și nu ne va merge sau ne va urmări în zone incalculabile.
În captura de ecran de mai sus vedem că inamicul a murit. Asta pentru că l -am lovit cu
două lovituri de topor. Inamicul s -a oprit din mișcare și corpul va dispărea în curând.
Următoarea imagine ilustrează pușca de asalt în timpul fotografierii. Putem vedea că blițul
botului apare în timpul fotografierii. Nu pot arăta acest lucru într -o imagine, dar pot asigura că
sunetul funcționează corect.
Sunetul de fotografiere funcționează numai atunci când apăsăm clicul stâng pentru fiecare
armă. Sunetul pașilor jucătorului funcționează atunci când ne mișcăm, ori de câte ori mergem,
alergăm sau ne g hemuim.Dacă inamicul reușește să -mi aducă bara de sănătate la 0, atunci voi
pierde controlul asupra personajului și mă va reapărea în locația inițială .
9
5. Concluzie
Scopul acestui joc a fost să te facă să uiți de problemele din viața ta pentru a te face să te
relaxezi și să -ți direcționezi concentrarea către obiectivele jocului.
Acest proiect a avut scopul de a crea un joc care să vă țină concentrat în timpul jocului și
să vă facă să încercați tot posibilul să supraviețuiți mediului dur al insulei st âncoase.
Am reușit sa fac startul in domeniul de dezvoltator de jocuri, deoarece acesta a fost primul
meu proiect de acest tip. A fost prima dată când a trebuit să lucrez cu Unity și sunt foarte bucuros
că am făcut -o pentru că până la urmă nu a fost atât d e greu, dar am avut o mulțime de caracteristici
de acoperit. Chiar dacă am lucrat cu alte limbaje de programare precum Java și C ++, simt că am
învățat C # și îl înțeleg mult mai bine.
Dezvoltarea acestei aplicații nu are sfârșit, deoarece putem adăuga o m ulțime de
caracteristici. În viitor, aștept cu nerăbdare să creez un sistem alimentar care să determine dacă
player -ului îi este foame si sa afecteze bara in sanatate în cazul în care player -ul nu a mancat de
o perioada îndelungată de timp.
10
Work planning
Task name Start Finish
Discussions with the
coordinating professor
23 O ctober 2019 12 N ovember 2019
Researching the required
environment dedicated to
the project theme
17 November 2019 19 January 2020
Downloading installing the
programs
21 January 2020 23 January 2020
Learning Unity thought a
set
23 January 2020 16 February
Strengthening
programming knowledge
using Unity and Visual
Studio
16 February 2020 27 February 2020
Following tutorials
dedicated to Unity
13 March 2020 25 March 2020
Implementing the
application
6 May 2020 15 June 2020
Writing the Diploma
6 August 2020 2 September 2020
11
1. State of the Art
1.1. What is a video game
A video game is an electronic game that interacts with a graphical interface to generate a
visual signal on a screen. Video games usually have a user reward system, most of the time the
score is kept, this system depending on the achieving of some objectives in the game. [11]
Playing video games is a way to relax and forget about the problems in your life while entering a
whole new world where you can do whatever you want without consequences. In this world you
will be a different person without responsibilities.
The first video games were created between the 1950 and 1960 by Jon Snell and were
designed for the oscilloscope, or EDVAC computers. A rocket simulation is the oldest vid eo game
which was created in 1947 by Thomas T. Goldsmith Jr. and Estle Ray Mann.
In present the games have evolved a lot. Now they have fancy graphics, complex stories,
multiplayer and a whole lot more features.
Games evolved on different types of platforms such as consoles, mobile and PC.
On the consoles side we have three competitors which are Microsoft, Sony and Nintendo.
Microsoft developed Xbox which has about 5 versions of it, Sony the PlayStation with 5
generations and Nintendo the Game Boy, The Switch and a lot more.
We are focusing on the PC platform which is easier to develop.
1.2. Games genres
1.2.1. Depending on the platform
First of all, framing a video game in one genre or another is done independently of the
elements of scenery or s tory and is based on gameplay. This means that the genres of video games
have in mind the type of actions that the player must take in a certain computer adventure.
If we use the criteria of the platform on which the games are developed, they can be games
for PC, console, portable console, mobile, browser games [9].
1.2.2 . Depending on the purpose of the game
Advergames are promotional software built to advertise a product or event.
The first goal of art games is catharsis, just like painting, sculpture or ballet, and not the playful or
entertainment dimension .Casual games are mainly games designed for mobile platforms that users
can play on the subway, in the car, in the office and that do not need a long -term commitment and
can be stopped at any time, are generally very easy to develop and do not require a substantial
financial investment from the creators and do not require special knowledge from the players.
Educational games are mainly used in schools to make learning a fun activity. If you answer
corre ctly the question of how much does 2 plus 2, the frog sings a song to you and if you manage
to name all the county residences correctly, you will receive an emperor's crown [9].
12
1.2.3. Depending on gameplay
Action games
The first major genre of video games is action games. These focus on physical challenges,
require good hand -eye coordination on the part of the player and excellent reaction speed. These
games are usually centered around the player, who controls most of the actions. Most video games
from the beg inning of computer history are considered action games and still represent a very wide
and offering category of games [9].
Platformer
A first subgenre of action games are platformer games. Some of the most famous adventures
of our childhood such as Prince of Persia, Super Mario or Donkey Kong fall into this kind of games.
These games are located in a setting consisting of several platforms hence the name. Games
of this kind take place in most cases in a linear 2D universe, but there are also many examples of
3D platformer games that stand out. An example of this would be Fez, one of the most award –
winning indie games of recent years.
From the point of view of gameplay, the platforms have a simple principle: the player guides
a character through obstacles an d enemies to move to the next level. These games often include
some standard moves such as jumping, climbing or shooting and some moves that defy the laws of
physics and make the game special [9].
Fighters & Beat 'em up
Another relevant category in action g ames are fighting games. They focus on simulating
melee fights against one or more opponents. And these games often involve very violent scenarios,
blood and unrealistic and exaggerated movements.
Although there are Fighting games that include melee weapon s that strike at close range, the focus
is always on fists and feet.
Beat games were the dominant genre of video games in the age of arcade games. In the late
1990s, however, this genre experienced a dramatic decline in popularity. There are currently only
a few titles on the market for beat games, and that's mostly because the developers haven't found a
way to take this genre further and make it less repetitive. The most relevant fighting game titles are
Mortal Kombat, Street Fighter and Tekken.
Adventure games
We're done with the action. Adventure games are some of the first games created and the first
examples appeared in the 70's. Although the first adventure games included only a text screen, in
the late 80's they were transformed into graphic experie nces. Unlike adventure movies, adventure
games are not defined by story or content. The adventure describes a gameplay mode that does not
involve fast movement or who knows what coordination but emphasizes exploration and solving
situations that require yo u to put your mind to the contribution.
This genre is considered quite "puritanical" and excludes any action elements beyond a mini –
game that appears at a certain point in the game. Because these games are not based at all on motor
skills that require ti me and exercise, the adventures have attracted those who do not normally play
13
video games. The genre peaked in the early 1990s when titles such as Day of The Tentacle, Sam
and Max and Myst became the best -selling games of the time. The simple 2D point and click
interface, the detailed and surreal worlds as well as the slow tempo determined people to try video
games and led to a maturation of the industry.
Shooter
A second subcategory of the "action" genre are shooters. In these games, the user uses
firearm s to shoot enemies. Most shooters involve violent gameplay, blood, war and wall-thrown
mice. But there are some examples, such as s platoon, which involve non -violent targets and use
only the mechanics of classic shooters.
The game that popularized the shoo ter genre is Doom, a classic of the 90's, not recommended
for people with motion sickness or weak angels. The most popular shooter of all time remains the
game Counter -Strike, which is still very much played and at a competitive level. The Call of Duty,
Halo and Far Cry franchises are the most relevant examples for this genre and that's because they
manage to combine an impressive variety of weapons and a huge universe populated by all kinds
of dynamic objects.
In addition, the multiplayer feature helps sho oter games grow in popularity because no matter
how fun it is to shoot computer -generated monsters, it's even more fun to play with friends or
cunning strangers.
Depending on the perspective from which the game takes place, the shooters are in turn
divided into two categories: first person shooters that put you directly in the character's skin and
see practically what he sees and third person shooters, in which the character is chased from behind,
which gives the player a wider field of view and better cont rol over the environment [9].
Survival games are a subgenre of action video games .
The gam es are set in hostile, intense, open -world environments. The players are equipped with
minimal equipment and have to survive the harsh environment as long as they can.
14
2. Theoretical Fundamentals
I chose this theme because I have always been concerned with computer games.
Among the advantages of using games are:
1. They have a therape utic effect for children with chronic diseases
2. Preschoolers better develop their motor skills
3. Video games reduce stress and depression
4. Relieves pain
5. Keep my heart healthy
6. They improve eyesight and keep the brain engaged
7. Improve decision -making skills [2]
2.1 Hardware
This game is designed to be played on the PC. First let’s learn a little about the platform on
which we will create the game.
In the mid -1970s, a new technology appeared: the mini processor. He used many transistors
connected to a silicon chip to make a computing device.
The first microprocessors were, by current standards, quite simple. The first microprocessor
became known as the 4004, from Intel. Microprocessors were originally used as a controller –
control devi ces – for dishwashers and refrigerators. Computer manufacturers and designers have
not missed the opportunity for these devices to be used as computers. The first successful product
was the Intel 8080 microprocessor and the new operating system called CP / M-80[10].
Today we have Intel and AMD dominating the processor market, creating multithreaded octa
core CPU -s that are affordable to almost everyone. Now the average RAM memory that a PC has
is 4 GB which was considered to be “overkill” 15 years ago. By “overkill” I mean that is more than
enough RAM (the system will never use all the memory). GPU -s producers which are NVIDIA
and AMD RADEON, launches video cards that have 8 GB video memory that are affordable. This
was unimaginable in 2005.
We can safely s ay that the technology evolved quickly, and the applications have developed
accordingly.
2.2 Software
Unity 3D is the most popular game engine [3] developed by Unity Technologies in order to
create content not only for a single type of platform, but for more than 25 different platforms
including desktop, consoles, mobile, and virtual reality, making it a cross -platform game engine
with unrivaled features.
Some of the platforms for which Unity can build applications are Oculus Rift, Google
Cardboard, Steam VR, PlayStation VR, Gear VR, Windows Mixed Reality, Daydream, Android
TV, Samsung Smart TV, TV OS, Nintendo Switch, Vuforia, I OS, Android, Windows , Universal
Windows Platform, Mac, Linux, WebGL, PlayStation 4, PlayStation Vita and Xbox One. Most of
the t ime, the engine is used to develop two -dimensional and three -dimensional games, virtual
15
reality and augmented reality applications, but also a lot of other unique simulations and
experiences. [4]
Due to the fact that it has a lot of professional tools beneficial for both a developer and an
artist (for example through powerful animation tools) Unity has attracted the attention not only of
game developers, but also of other industries outside the are a of video games such as: architecture,
engineering and construction, film industry and automotive. In engineering world, Unity is a tool
that allows many innovative ideas to be brought to life through a real -time development
environment.
When it comes to movies, animations and visual entertainment, Unity presents an unlimited
number of opportunities. Through this platform, you can create TV series, full -length films, but
also CGI short films, all in high definition and with a high degree of details.
Among these creations are “Mr. Carton” by Michaël Bolufer and Fabien Daphy which is the
first cartoon series made with Unity and produced for televisions, “Gian Bear” by E→D Films,
“Sonder” by Soba Productions – a 13 minutes short film which combines complex 3D environments
with two dimensional animations, and many more. [5] In the automotive industry, unity can be
used to create prototypes and test them in a virtual environment. In addition, it is possible to export
data from platforms such as CAD and VRED.
Some of the important functionalities of this game engine from a technical point of view are:
Creating and Destroying Game Objects
Dealing with Vector Variables and Timing Variables
Access the Components
Events for Game Objects
Physics Oriented Events
Coroutine and Return Types
The gaming industry is relatively young but with a rapid and impressive evolution, still being
in the users' attention, especially since the 70s and 80s.
It has numerous versions, ranging from total free (not even credit card nee ded, life time!), to
pro versions for big teams and professionals.
Unity is used to create half of the world’s games. Our real time platform, powered by tools
and services, offer incredible possibilities for game developers, and creators across industries and
applications. [6]
The themes of the games are very varied and can be divided into several categories such as
action adventure or simulators resembling a lot of scenes from movies only in this case the player
contributes directly to the action which lea ds to an accumulation of adrenaline much higher than in
the case of films. It also leads to an increase in the ability to concentrate and an increase in the
reaction speed of the participants.
What makes this platform much more accessible is that even tho se with less experience and
a lower level of programming knowledge can create simple types of games.
There are two types of programming languages compatible with th e Unity platform, namely
C # which is very similar to C ++, this being an object -oriented programming language with the
main feature if I programmed the scripts correctly and all the code execution time is very low an d
second Unity script language w hich is a language specially create d for Unity .
Scripting
As mentioned above, the C# programming language is used to write scripts in Unity. C # is
among the most used programming languages in the world. It is a simple, modern language, with
16
a great deal of flexibility in terms of application development and portability. Among the main
qualities of language, we can distinguish: modernity, simplicity, general utility, high productivity,
stability in complex applications, durability, is a total object -oriented language (any entity in this
language is actually an object), provides full support for the development of necessary components
in distributed environments, so it is also a component -oriented programming language.
In Unity, each Game Object has a behavior which is controlled by t he Components attached
to it. Unity’s built -in Components can be very flexible. However, if a game developer wants to
build his own game features, he must cross their barrier and create personalized Components using
scripts. These allow game events to be t riggered, Component properties to be modified over t ime
and responses to user input [7]
Scripting represents an important aspect in all applications created with Unity. Almost all
applications need scripts to respond to user input and to schedule events in the gameplay to happen
at the right time. In addition, scripts can be used to control the physical behavior of objects, to
create graphic effects, or even to implement a custom artificial intelligence system for game
characters. [8]
The physical behavior of the objects as well as the graphic effects used are created using
the scripts being created directly from Unity
The creation of the stage is also very important.
The scene consists of the game objects that create the menu as well as the game levels.
A scene may contain the game environment decorations, obstacles or other components of
the game
The artificial world that we can create with the help of this platform is built piece by piece
depending on the result we want to achieve.
17
3.Implementati on
3.1 Downloading the required programs and creating a new project
For this project I used Unity version 2020.1.3f1 downloaded from their website and I also
used Visual Studio 2017. To create a new project in unity we have to open unity hub and click on
new. Now we'll have to choose on which template do we want to create the project and also where
to save it and its name. In my case the template had to be 3D. Once we click next , now we will see
on the left side our hierarchy, in the middle we will see the scene and the game window, on the
right side we will see the inspector and on the bottom we can see the project folder and its folders.
The hierarchy shows us our scenes components and the sub components which are called
children of the components.
The scene window allows us to work on the map and the game window shows us the camera
perspective.
Inspector tab allows us to see, add, and modify the properties of each component or
subcomponent.
The project window provides a quick way to navigate through al l the folders of the the project
for example we can quickly see all the components of our assets folder or navigate between the
scripts faster.
3.2 Creating the terrain
3.2.1 Sculpting the terrain
One of the most fun part about creating your own game is making your terrain. Unity has
tools designed specifically to sculpt, paint and detail terrain within the unity editor. First of all I
had to make sure I have the unity version 2019.1 .5 or later. With this version installed we have to
click on window and package manager. Here we have to make sure that we have all packages
selected then click on the advanced and show preview packages. Then if we search for terrain tools
we should be able to find the version 1.0.0 and install it. This was the case when I fir st started to
work for this project. Now we should be able to see the terrain tools sample asset pack just by
clicking windows and asset store.
Figure 1. Terrain Tools .
18
The cool thing about this pack is that it comes with a lot of brushes and some preinstalled
textures that we can use. Now all we have to do is to press download and then import and we are
good to go. Now it’s time to create a new terrain.
We can do this by Simply right clicking on the hierarchy, 3D object and selecting terrain.
This is going to sound a huge piece of terrain in our scene. If we look on the right side of the screen
we will see the inspector and indeed inspector we have a terrain menu where we have a settings
button. If we press on the settings button we will see an opti on called mesh resolution. Here we can
set the train width, length and height along with the detail resolution. For this terrain I chose 300
width, 300 length and 300 height.
Figure 2. Terrain Settings .
After we created this we can observe that in our sample scene we have a new component
called terrain and if we click on terrain it has two more components. One of them is the terrain
component which allows us to modify the aspect and the other component is called terrain collider
which decides how the o ther components will interact with a heart terrain .
So at this point we are ready to sculpt our environment. I have to select the paint tool and
with this selected we get a bunch of options. We have to make sure that we have the raise or lower
option selec ted to be able to create mountains and other type of structures because at the moment
we have a plane field. Select whatever type of brush we prefer and under our brushes options we
have the brush size and opacity of the Brush. With the size option we cont rol how big is the surface
that we want to Rise or lower and with the opacity we control the strength of the sculpting.
19
Figure 3. Terrain Sculpting .
If we want to have a plain surface we can use the option set height and there we can insert
the height that we want our surface to remain at. If we notice that our edges are sharp we can adjust
that by selecting the smooth height option where you can smooth out any region or surface of our
terrain.
3.2.2 Painting the terrain
The next part of the process is painting. We also do that with the paintbrush but we have to
change the mode to paint texture. When we work with paint texture we use what is called terrain
layers .Currently there are no layers so we must hit layers and create layer. This is going to ope n a
window where we can select the texture. I used the snow texture that was preinstalled with the
terrain tool. After I added the texture it can be found in the terrain layers.
Figure 4. Terrain Texture and Layers .
You can have how many textures you want to the terrain but I only used the snow one and
then I just simply painted the whole map with this texture.
20
3.2.3 Trees grass and buildings
The next stage is to add some vegetation and some buildings so for that I clicked Windows
Asset Store and I se arched for some models created by other people and I found Winter Forest –
Low Poly Toon Battle Arena / Tower Defense Pack.
Figure 5. Winter Forest Pack.
After I downloaded and imported the Pack in my project I had to go back in the terrain
inspector and select the option paint trees. Now we have to click on edit trees, add tree and select
what type of tree we want from the prefab folder of the Pack we just downloaded. With this option
we can also add grass not only trees. Also , we can select the brush size, the tree density and the
tree height. It has an option which can set random values to the tree height.
Figure 6. Winter Forest Pack .
21
Adding trees and grass in our terrain is a similar process to the texture process. We only have
to select the locations where we want vegetation with the brush and by simply clicking it will add
trees or grass in our wanted zone.
Figure 7. Terrain Trees .
22
Figure 8. Positioning Buildings .
If we want to add buildings or other
objects we have to do that manually. For
example if you
want to add a building you have to go in the
prefab folder and drag and drop the building
that you want in the hierarchy zone. I added
the buildings and the other objects in the
terrain component me aning that the buildings
and the object are children of the terrain
component. Now we have to position the
building using the transform function located
in the inspector. The transform function
allows us to position rotate and scale the
object using the th ree axes x, y and z. After
we positioned the building , we have to make
it a “rigidbody ” and also a box collider by
clicking on the button add component.
Figure 9. Positioning Buildings .
The function “rigidbody ” gives our building a solid
body so that it can interact with physics and the box
collider function creates the zone which interact with
the terrain or with the player (basically it makes a
physical body not just an image in which you can enter
with the pl ayer).
Where do the same thing with all the objects that we
want to add one by one.
23
3.3 Creating the player
3.3.1 Creating and positioning
The first thing to do is right clicking on the hierarchy and creating an empty object and
renaming it two player. Then with the transform function we can put the player where we want to.
In my case x=285.38, y = 15.278 and z = 215.25. These are the coordinates where we will start in
the game.
3.3.2 Character controller
Next , we are going to attach to our player a character controller component which basically
creates the physical body of our player.it has the form of a cylinder and from the settings with can
adjust the height radius , center and so on.
Figure 10. Character Controller
The slope limit will limit the player to climb slopes that are less in degrees than the value entered.
In my case it’s 55.
The step offset limits the player to step over only objects that are less than 0.2 in height.
The skin weight allows the player to penetrate other objects within the value 0.08.
The minimum move distance denies the player to move below the value indicated.
The cen ter is basically the offset where you put the collider on the player.
The radius is essentially the width of the collider ( Player).
The height option is the height of the collider.
3.3.3 Camera
The next step is locking the camera on the players angle. In order to do that we must right
click on the Player and create an empty object which I renamed it Look Root. After that we make
the camera children of Look Root and we reset the transform of the camera. This is how we're
going to see from the first -perso n perspective. This is the main for perspective the main camera.
Will also had the second camera to the look root which will display only the weapons. So the
first camera will display everything and the second camera which is called FP Camera will display
only the weapons.
3.3.4 Positioning the weapons
For this I found a pack that contains animations and models for the player and the enemy. I
imported it in the project.
24
In order to add the weapons we must go in the folder of assets > models > first person > all
animations. Here we can find plenty of weapons to be added to our character. First we need to add
texture to our weapon. In order to do that we have to enter the asset folder and right click < create
< material.
Figure 11. Weapon/Enemy Material .
Here we can choose the color we want for the weapon and the players hands.
In order to add the texture to our weapon we have to click on the axe. Here we noticed three
components: armature, arms and axe.
The ones that we want to add texture or arms and axe. To add the material we simply drag
and drop the material in the inspector tab on the right. We can add materials to any 3D models.
Once we added the material through every weapon , we now can right click on “Look Root ” and
create an empty object wh ich we will rename it to FP Weapons. Here we drag and drop every
weapon we have making them the children of FP Weapons.
25
Figure 12. Adding Weapons .
Now we have to position every single weapon to the player in such a way that the camera
sees the weapon. We do the positioning using the transform function, changing the values of x, y
and z.
Figure 13. Positioning Weapons .
In order for FP Camera to see only the weapons we must create a new layer called
“FirstPerson ” and changing the layer of the weapons to “FirstPerson ” from default.
3.3.5 Player’s movement
Now we have to program the player’s movement. In Order to do this , we have to go In the
“Asset” folder In The project tab and create new folder which we will name it “Scripts”. In this
folder we will Store All our source code. Now In this folder we will right Click and create a new
C# script. We will remain the script on “PlayerMovement”. Before we start coding we have to drag
and drop the “PlayerMoveme nt” script to the “Player” object located in the hierarchy window. This
means that the script will only work for the object “Player”.
Now we have to program the movement. For the movement we only have to bind the “w a s
d” keys to the axis x and y to move forward, backward, left, right and to set a speed for the player.
To jump we have to create a function to check if the player is on the ground for not. If it is on the
ground then he is able to jump using the “space” key, if it’s not on the ground then it won’t be
allowed to jump.
Figure 14. Player Movement Script .
After we write the code we can adjust the speed and the jump force in the Inspector tab.
26
3.3.6 Mouse look and mouse controls
Now that our player is able to move and jump , we can create the “mouselook” script which
will allow us to move around the mouse and orientate ourselves in the space. We have to follow
the exact same steps that we did with the “playersmovement” and jump script which is creating a
new C# script in the Scripts folder. The only difference is that we attach it to the “Look Root”
object which is a child of the ”Player” object , located in the hierarchy.
This script allows the camera to rotate with the mouse coordinates (x and y) and makes the
player rotate in the given positio n.
Figure 15. Mouse Look Script .
“Can_Unlock” Hiddes the mouse cursor so we don't see it during the game.
If we check “Invert” option it will invert the coordinates of the mouse (horizontal becomes vertical
and vertical becomes horizontal).
“Sensitivity”Allows us to control how fast we want to move the mouse.
“Defalt_Look_Limits” are limits of the mouse rotation. If we try to go over these values it will not
allow us.
“Roll_Angle” and “Roll_Speed” will not allow the camera to roll during rota tion (it will remain
steady).
3.3.7 Player’s Sprint and Crouch
Let us now create the sprint and crouch function. We have to do the same steps as before.
Right click and create a new C# script in the Scripts folder called “PlayerSprintAndCrouch” and
attach it to the ”Player” object , located in the hierarchy.
For the sprint function we have to Increase the speed of the player while holding on the “left
shift” key and we must make sure that the player can't sprint while he is crouching. We have to
make the pla yers sprint for a limited period of time such that the player can only sprint for a couple
of seconds. After that he is only able to walk but the player can regenerate the stamina so it takes
double the time to fully sprint again.
For the crouching functio n if we press the “c” key we only have to lower the camera and to reduce
the speed of the player.
27
Figure 16 Player Sprint And Crouch Script.
In the inspector tab we can adjust the settings of the sprint and crouch functions.
3.3.8 Player’s Footsteps Sound
For these we have to once again create a new C# script inside the “Scripts” folder and rename
it to “PlayerFootsteps”.
Now we have to right click on the “Player” object located in the hierarchy window and create
a new object which we will rename it t o “Player Audio” and then we will drag and drop the
“PlayerFootsteps” script on “Player Audio”.
Figure 17 Player Audio Object
The first thing that we need in the Script is to allow us to to attach footstep sounds for the player.
Figure 18 Plyer Footsteps Script.
In the inspector tab we can select the “size”. This represents the number of sounds that we
can insert. In our case we choose 4 so we can add 4 audio components.
The audio components are located in assets > Sounds > Footsteps.
Here we have different types of sounds but I chose the dirt ones.
The next thing we have to do is to click on “add component” in the inspector tab and select
the audio source so that we can attach the component. We also have to turn off “Play on awake”
because thi s function allows the audio to be played at the start of the game and we don’t want that,
we only want to play the audio while walking or sprinting.
28
Now we have to implement a function that checks if the player is on the ground or not. This
makes sure that the footstep sounds are played only when the player is on the ground. This means
that the sound will not be played if the player is jumping or falling.
The next thing is to create a function that makes the sound be played more often if the player
is sprin ting than walking or crouching.
We also have to set the volume of walking lower than the volume of sprinting and of course
the volume of crouching being lower than the volume of working.
3.3.9 Animating Hands and Weapons
Up until now we have the map, the player, the player controls, player sounds, the weapons
but now we have to animator weapons.
Figure 19 Weapon Animations.
The animations that we are going to use are located in Assets > Models > First Person > All
Animations.
Do you use the animations we will need what is called “animator controller”, but we will
need 6 of them, one for each weapon. For that we will need a new folder which I'll rename it to
“Animation Controllers”.
The first controller will be for the axe, named “Axe Controller”.
We hav e to drag and drop the controller in the “controller” option under “Animator” in the
inspector tab of the “1 -Axe”.
Figure 20 Linking Animation Controller.
In order to work with the controller , we have to open the animator tab by clicking on
Windows > animation > animator.
29
In the animator tab we work with what is called “animation state”. The animation state
represents the action or the event which is being animated.
The axe has five animation states which are Draw, Hit, Hold _Pose, Holster, Idle and M iss.
Figure 21 Animation States.
Each one of these has a different animation.
Figure 22 Animation State.
Figure 23 Configurating Weapon Animator.
The animator works similarly to a diagram. The first action that we are going to do is to draw
the weapon so that is the first state.
30
After we draw the weapon we want to stay on idle so the second state will be idle. Notice
that there are no arrows back t o the “draw weapon” because once the weapon is out , we cannot
draw it anymore so it stays in an “idle” state.
Now we want to attack and after that we want it back to be in the “idle” state so we have to
put an arrow back to “idle” state.
We can use the sam e animator controller for the revolver, assault rifle and shotgun.
Figure 24 Configurating Bow and Arrow Animator
For the spear and bow we need a separate controller because we have 1 more animation
which is “Aim”. Notice that it's similar to the other controller but we first have to aim and then we
have to shoot with the spear or bow.
3.3.10 Weapon Handler
The weapon handler is a script for controlling the attributes of weapons.
But first we have to move the Script in its own folder and for that we will create a new folder called
“Weapon Scripts” in the “Script” folder located in the “Assets”.
Since we have different weapons for example we have an axe we have a revolver or we have
a spear. We're going to have a script that it's going to handle different situations with different
weapons. For example , we have to make the Axe being melee and not shooting a bullet.
31
Figure 25 Weapon Handler Script
Here we have to select the options for every weapon.
3.3.11 Weapon Manager
The weapon manager is the script for controlling the switching between weapons in our
game. In the “Weapon Scripts” folder we will now create a new C# script called weapon manager
and just as before we have to drag and drop it on the “Player” object.
The purpose of this script is to allow us to choose different weapons in the game for example
if we press the key 1 we select the axe if we press the key 2, the revolver and so on.
Figure 26 Attaching the Weapons to the Script
Here, after we selected the amount of weapons, we had to insert the weapons from the
hierarchy in the inspector > weapon manager. Then, in the script, we simply have to create a
function which activates every weapon depending on which key you press (form 1 to 6).
Also , we have to make sure that if you already have the axe (meaning the key “1”) and you
press the button for axe again, it won’t bring up the axe.
3.3.12 Player Attack
This is the script for controlling the shooting with the selected weapon. Once again we have
to create a new script called “PlayerAttack” located in the “Player Scripts” folder and attach it to
the player object.
In this script we have to link the “WeaponManager” so it knows what to do with what
weapon. We have to create and call the “shoot” function when we press the right click button of
the mouse. The “shoot” function calls the attack animation and deals damage to the enemy.
32
We also have to keep in mind that not every weapon shoots a bullet so we have to put a
condition that if the bullet type is “bullet”, it will shoot a bullet, but if th e bullet type is “none” then
it will only play the animation without dealing damage with a bullet. We have to set the “Transition
Duration” and the “Transition Offset” to 0 so that we can shoot or attack during the idle animation
without waiting for the id le animation to be finished.
Figure 27 “Transition Duration” and the “Transition Offset” off .
We can do this by selecting the attack arrow from “idle” to “attack” and then clicking on the
settings toggle. We also have to the reverse, selecting the attack arrow from “attack” to “idle” and
checking the “has exit time” and setting the “exit time” to 1 so it can finish the shooting/attack
animation.
33
Figure 28 Configuring Idle/Attack States.
3.3.13 Creating the Zoom Effect with animations
For this we have to click on Player > Look Root > FP Camera from the hierarchy and in the
inspector tab we have to add an animator from the “add component” button in the inspector.
The next step is to create a new folder called “FP Camera Animations” in the “Asset” fo lder
and create an animator controller named “FP Camera Controller” and then drag it in the animator
tab in the inspector window of the FP Camera object.
Figure 29 Linking the FP camera Controller
The next step is to create a new animation from the “animation” window (Window > Animation >
Animation) which we will call it “ZoomIn”. Here we only have to change the position of the pistol
/ shotgun / assault rifle to look like it's zoomed using the “transform” and setting it to the end of
the wished peri od of time.
Figure 30 Creating Zoom Animation.
In the animator we will create an “idle” state, a “ZoomIn” state which will have our zoom in
animation and a “ZoomOut” state which will be the reverse of the “Zo omIn” animation so it will
come back in the “i dle” state in a smooth way.
34
Figure 31 Configuring Zoom Animation.
Now in the “PlayerAttack” script that we created last time, we have to set only the weapons
that shoot to zoom in and out (so that we can’t zoom in with the axe). We also have to bind the
right click to the zoom animation such that it will only zoom in when we hold the right click.
We need to uncheck the loop time of the “ZoomIn” animation because we want it to remain
zoomed, we don’t want it to repeat.
Figure 32 Unchecking the Loop Time.
We have to do the same thing to “ZoomOut”.
3.3.14 Creating arrow and spear bullet
You must create different projectiles for the arrow and the sphere because they cannot
shoot bullets. If we type “arrow” in the search bar, we can find the model of it.
Figure 33 Bow and Spear Model.
35
We will use this model for both spear and bow except that for the bow we will scale it to
½.Now we simply drag and drop the arrow model in our “Sample Scene” located in “Hierarchy”.
We will use the same material that we used for all the other weapons. I'm going to attach a
“rigidbody” and also a “box collider” component so that the arrow is solid. After this we have to
create an arrow tag so that the game will know when we call the arrow.
Now it's time to create the “Arro wBowScript” in the “Weapon Scripts” folder.
In this script do we have to make sure that the arrow only appears when we click on the left
click and we also have to make sure that the arrow launchers at an appropriate speed. Since it's a
rigid body it will a utomatically fall and won’t fly like a bullet and because it has a box collider, it
will not fall under the map.
To make sure that the arrow is facing the right way we have to lock it to the camera so that it
will fly facing the direction of the camera. Once we're done scripting we have to drag and drop the
the arrow and the spear in the the locations in “Player Attack” script.
Figure 34 Player Attack Script.
The next phase is to attach the script that we wrote, “ArrowBowScript”, to the arrow and to
the spear.
Figure 35 Arrow Bow Script.
3.3.15 Configuring and animating the cannibal enemy and creating the enemy
animation script
Just like we did with the weapons we have to add the cannibal in our hierarchy.
The Cannibal model is located in Assets > M odels > Characters > Canibal.
36
Figure 36 Enemy Model.
We will apply the same material for the texture like the one that we used for the weapons. In
order to make the enemy solid we have to add a “Rigidbody” and a “Box Collider”, just like before.
In this case we have to adjust the “Box Collider” to embrace the whole character so we will set the
size to be Vector3(0.280000001,1.75,0.209999993).
Figure 37 Configuring the Enemy Box Collider.
Just like we did with the weapons we have to create a new animation controller for the enemy
to properly use the animations. In order to use the animation controller we first need to create a
new animator in the inspector tab and after we created it we have to drag and drop the animation
controller in the “contro ller” place. We will rename this cont roller to “Cannibal Controller”.
37
Figure 38 Configuring the Enemy Animator.
Just like in the case of the weapons animation we must use multiple animations. In this case
we will use idle, run, attack and walk. Almost all the transitions must be connected vice versa,
except for the “attack” and “run” because we don’t want the enemy to attack while running.
Now it’s time to create the “Enemy Scripts” folder, located in the “Scripts” folder and then
we create the “EnemyAn imator” script in the “Enemy Scripts” folder. This script connects the
animations of the model (Idle, Run, Attack and Walk) to the animator controller.
Figure 39 Enemy Animations.
Here we have more animations but we will only use the ones of the above.
3.3.16 Enemy Controller
It’s time to create the script that will control the enemy’s AI and make him walk and attack
the player. In order to make the enemy move around the map , we first need to make sure that our
terrain is walkable. We do this by checking the “navigation area” to “walkable”.
This option can be found in Window > AI > navigation > Object.
38
Figure 40 Navigation Tab.
Once we did that you will see a blue area and a normal area. The blue area is the walkable
one and the normal area is the non-walkable one. The blue area is free of vegetation and buildings
so that the enemy won’t be able to walk there. This process is made automatically by unity, so you
don’t have to choose the walkable area yourself .
Figure 41 Walkable Areas.
It’s time to create the “EnemyController” script located in the “Enemy Scripts” folder. We
have to attach the script to the “Cannibal” object. Discrete will determine wherever the enemy will
patrol, chase or attack. For the patrol function we have to make the e nemy move randomly in the
walkable area within a minimum and maximum radius and to connect it to the walk animation.
39
Also we created a timer which will determine how many seconds the enemy will patrol in a
location before heading to the next random destina tion. For the chase function we have to set the
distance in which the cannibal will start to follow the player (the line between patrol and chase)
and the speed of the enemy while connecting to the running animation. We also need an attack
function which w ill call the attack animation.
3.3.17 Detecting and dealing damage
Now we have everything we need in order to detect the damage between the enemy and the
player. First we're gonna start with the player. We will attach an attack point for the “Axe”.
The at tack point will be the point which when will collide with the enemy will deal damage.
We will create the “Attack Point” in Player > Look Root > FP Weapons > 1 -Axe > Armature >
Arm_R > Forearm_R.
Figure 42. Creating Attack Point.
Next we create the “AttackScript” in the folder “Player Scripts” and we attach it to “Attack
Point”. This script reads if the “Attack Point” is touching an enemy or in the case of the enemy, a
player and if it’s true, it deals damage. It is creating a sphere where the “Attac k Point” is and if it
collides with a player or enemy it damages them.
Figure 43 Attack Point Script.
We don't want the “Attack Point” to be permanently on so we have to choose when we want
it to be on. In order to do this we have to select the Axe and going the animation tab and select the
“Axe Attack”.
40
Figure 44 Attack Point Event.
Here we have to select the frame in which we want the “Attack Point” to be active and the
frame in which we want to turn it off. I chose frame 4 to activate the “Attack Point” and frame 14
to deactivate it meaning that i will only deal damage to the enemy during this period of animation
(frame 4 -14). We activate the “Attack Point” by creating a new event in frame 4 called and then
we choose the function that we want, in this case “Turn_On_AttackPoint”.
Figure 45 Attack Point ON
We turn the “Attack Point” off by adding a new event in frame 14 and choosing the function
“Turn_Off_AttackPoint”.
41
Figure 46 Attack Point OFF.
The next phase is creating the “AttackPoint” for the enemy
We create the “AttackPoint” in Cannibal > Armature > Hips > Middle_Spine > Chest >
Shoulder_R > Arm_R > Forearm_R > Hand_R.
Figure 47 Enemy Attack Point.
We attach the “Attack Script” script to the “Attack Point”, just as we did with the axe’s “Attack
Point”.
Similarly to the player’s process, we turn the “Attack Point” on by adding a new event in frame 38
and choosing the function “Turn_On_AttackPoint”.
42
Attack Point ON
We turn the “Attack Point” off by adding a new event in frame 55 and choosing the function
“Turn_Off_AttackPoint”.
Figure 48.Attack Point OFF.
43
3.3.18 Creating the Health Script
The health group is universal meaning that both the player and the enemy will use it to
actually take damage. We will create our script named “ HealthScript” in the “Player Scripts” folder
and will be attached on the player and on the enemy. This script will allocate the health number to
the player and to the enemy and when the number will reach 0 in case of the player it will respawn
the player i n the initial location and in the case of the enemy it will make it disappear from the map.
The default value of the health will be 100.We will have a function called “is_dead” which
checks whatever the number reaches zero then it checks if it's a player or an enemy and depending
on the result it will either respawn it or make it disappear.
It knows if it is a player or an enemy Because the player has the “player” tag and the enemy has
the “ enemy” tag in the inspector tab.
Figure 49 Health Script.
3.3.19 Creating Player and Enemies sound effects and shoot effects sounds
We will start by creating the “Player Axe Whoosh Sound” script in the “Player Scripts”
folder. This script allows us to add more than one sounds to the effects. In order to add sound s we
need to click on the “Add Component” and select the “Audio Source”. Now we need to attach the
“Audio Source” to the “Player Axe Woosh Sound” script. In the “size” option we will enter the
value 3 so we can add 3 sounds.
The sounds that we want to add are located in asset > sounds > wooshes. We now only have
to simply drag and drop the sounds in the element column in the inspector tab. Just like we did with
the “Attack Point” we have to go in the animation tab and select the frame where we want the sou nd
to start and add a new event and select the function “PlayWooshSound”. I used frame 5 for this.
Figure 50. “PlayWooshSound” Event.
Notice that we now don't have to select the frame to stop the sound because the sound will
automatically stop. In the case of the revolver we only have one sound and that is the shoot one so
44
in the animation tab we have to select the frame that we want and add a new event and select the
“Play_ShootSound”.For the assault rifle these are the same steps.
With the s hotgun what we have to do besides heading the shooting sound is heading the
reload sound so here we must add a new event in the animation tab and select the
“Play_ReloadSound”. In the case of the spear and the bow we don't have any sound .The next thing
to do is to add the muzzle flash effect for the revolver shotgun and the assault rifle. The effect is
located in assets > effects > muzzle flash. We drag and drop the muzzle flash and make it a child
for revolver, shotgun and assault rifle.
The next thing to do is to position the muzzle flash in the right direction for every
weapon. We do that by using the transform tab located on the right side of the screen. After that
to make the muzzle flash appear and disappear , we have to create new events in the shooting
animation for every weapon just as we did with the sound effect and select the frame where we
want the flash to appear and select the frame where we want it to disappear.
We have to give our enemies some sounds so we create a new script called “En emyAudio”
and attach it to the new game object which we created as a child of “Cannibal”, named “Cannibal
Sound”. This script makes the enemy play different audios, depending on the situation. If they
chase us, it will play “scream_Clip”, if they attack it will play “attack_Clip” and if it dies it will
play the “die_Clip”.
Figure 51. Enemy Audio Script.
Now we only have to put the right sound in the right order. The sounds are located in Assets
> Sounds > Cannibal.We have the size of 3 in the “Attack_Clips” because we want to play more
than one sound when he attacks the player. In the script we made the sound louder or quieter
depending on the distance between the player and the enemy.
3.3.20 Creating the User Interface and Menu
The first thing that we are going to create is the crosshair. We will right click on the hierarchy
and select the UI > Image. This will automatically create a canvas. The canvas is a required object
for every UI element. I will call this canvas the “crosshair canvas” an d the image “crosshair”. The
picture that I'm going to use is in assets > UI. In order to view the crosshair properly, in the inspector
tab we click on the “Texture Type” and select “Sprite (2D and UI)”. Now we are able to drag and
45
drop the image in the in spector tab of the “crosshair” object in “Source Image”. Now we are able
to see our crosshair on the screen. Next we have to position the crosshair where we want it and then
scale it in case it’s too small or too big.
Figure 52 Crosshair.
The next UI element will be the health background. For this we will create a new canvas with
the child called “Health Background”. Here we will simply click on the color option in the inspector
tab, choose the wanted color and then we will position it and scale it where and how we want. I
positioned it in the left corner of the screen.
Now we will create a new child of “Health Background”, which will be our health icon. Just
like in the case of crosshair we will make it a “Sprite (2D and UI)” and then posi tion it over the
health background. How we will create the health bar.
We repeat the same steps that were made during the health icon process and after we
positioned the bar we have to select “filled” in the “Image Type” option in the Inspector tab. We
will select the “Fill Method” to be “Horizontal” and the “Fill Origin” to be “Left”. This allows the
health bar to decrease in case we receive damage.
We repeat the exact same process for the sprint bar (with different icons and colours ).
46
Figure 53 Healt h and Sprint Bar.
We have to create a script that connects the UI to the stats themselves. In the “Player Scripts”
folder we will create a script called “PlayerStats”.It will be attached to the “Player”and in it we
created the reference for the images which will be controlled by the script.
For the main menu we have to create a new scene called “Menu”. I copied the scene and
disab led the player and weapons and locked the camera on a single spot.
Here I simply created a new canvas and created a child cal led “MainMenu” and two children of
the “MainMenu” called “Play Button” and “Quit Button”. I positioned the buttons where I wanted
them to be. I created a new script called “Main Menu” which changes between the scenes if i press
the button “Play” and quits the game if i press the button “Quit”.
Figure 54 Main Menu
47
4. Experimental Results
Since this project was built from scratch there were multiple objectives that had to be
fulfilled. I chose to highlight these objectives using multiple screenshots proving that they work.
The first thing that we are going to do is launching the game from the exported game folder.
Figur e 55. Game Folder .
4.1 Main menu
After we launch the game the first thing that welcomes us is the main menu. Here we notice
that the two main buttons, “Play” and “Quit” are working properly. If we press “Quit” we quit the
game, if we press “play” we are going to the next phase which is starting our survival adventure.
Figure 56. Main Menu .
48
4.2 Gameplay
Once we press the “Play” button we are at the spawning location of the player.
The first thing that we are going to see is the environment, meaning that we successfully created
the terrain with all its components (vegetation and buildings).
The next object that we are going to not ice is that the weapon is the axe which is weapon #1
so we know that the “Weapon Handler” script is working. Also the axe is aligned correctly.
Then we can observe the UI. We can see that the crosshair is in the middle of the screen and
that the health and sprint bar is located on the top left side of the screen. We can also notice that
are health is decreasing because while I was taking the screenshot, the enemy which is found near
the players spawn location attacked me several times dealing damage. In this way we also know
that the damage system works fine.
Figure 57. First Person .
Here I captured every weapon available in the game.
49
Figure 58. Weapons .
In the next screenshot we can notice that the sprint bar lowered its value because I was
running away from the enemy indicating that we can move around with the character a nd also move
the camera view with the mouse.
Also in this image I was holding the right click b utton so it was aiming the spear at the enemy.
We can see that we can see the enemy is standing in an empty location, meaning that it’s a walkable
place. Knowing this, we can assume that the “patrol” function of the enemy is working fine and it
won’t walk or follow us in unwalkable areas
Figure 59 Enemy.
50
In the next screenshot we see that the enemy died. That’s because I hit him with two hits of the
axe. The enemy stopped moving and the body will disappear soon.
Figure 60. Dead Enemy
In the following picture I threw a spear in the air, showing that the spear model in deed spawns and
it’s flying in the ri ght direction facing the camera.
Figure 61. Bow Bullet .
51
The next image illustrates the assault rifle while shooting. We can see that the muzzle flash
appears while shooting. I can’t show this in a picture but I can assure that the sound is working
properly. The shooting sound works only when we press the left c lick for every weapon.
The player footsteps sound is working when we move, whenever we’re walking, sprinting,
or crouching.
Figure 62. Weapon Shooting .
If the enemy manages to get my health bar to 0, then I’ll lose control of the character, and it
will respawn me to the initial location.
Figure 63 . Respawning after being killed
52
5. Conclusions
The goal of this game was to make you forget about your problems in your life to make you
relax and direct your focus into the objectives of the game.
This project had the purpose of creating a game that keeps you concentrated during the gameplay
and makes you try your best surviving the harsh environment of the rocky island.
Keeping this in mind we also realised to achieve self -improving as a game developer since
this was my first project of this type. It was the first time I had to work with unity and I'm really
glad I did because in the end it was not that hard but I had a lot of features to cover. Even if I
worked with other programming languages such as Java and C++ I feel like I learned and improved
a lot with C# and I understand it much better.
As a short recap of all that we presented above this game was intended to give the user the
opportunity to relax and to be entertained while playing the game. I consider this goal achieved
since we managed to create and decorate a map, to give the player the ability to move and look
around, to give the player different types of weapons and animating them.
The greatest thing is that we managed to create an enemy with artificial intelligence (AI)
that attacks because without an enemy this game wouldn't give you the thrills and the excitement
required to enjoy it. We managed to create stats for the player which gives you information about
his health and stamina so t he user can easily know when he's at his limits.
For this application I tried to create a lot more features but I didn't have the chance to finish
them. One of the features that I wanted to be in the game is a respawn of the enemies which is
randomly plac ed when the player kills one of them. At this moment there are a fixed number of
enemies which are always placed in the same location.
The growth of this application has no end since you can add a great amount of features. In
the future I'm looking forwar d to creating a food system which determines whatever you are
hungry. The first phase will be to limit your stamina if your food bar is low and the next stage will
be to lower your health bar if you have your food low for a long period of time.
I also wan t to add weapons which can be found around the map and add a system which
limits the bullets of the player. Along with this I want to implement cars and different ways of
transporting the player from one place to another. This will be complicated since we need to
simulate the driving of the car or if we want to create a plane we need to simulate the flight.
The most important thing that I want to add in the game is a sea around the terrain which
can be explored. Along with the sea I want to add boats and o f course we need to add fishes and
other types of underwater creatures which will interact with the player. For example if you will kill
the fish it will give you food and increase your stamina. If you get ambushed by a shark in the water
you will instantl y die since, like in the real world, the shark is stronger than you and if it attacks,
you will certainly die.
In the final development stages of the game I would like to post it on Steam and other
platforms that sell games and receive feedback from the users.
53
6.References
[1]D.Vi șan, Limbajul C++ fără profesor, 2 nd ed.,Ed.Else, Craiova, 2016
[1]E.Cerchez and Marinel Șerban, Programarea în limbajul C/C++,Metode și tehnici de
programare, Ed Polirom,2006
[2] (2013) https://www.csid.ro/health/sanatate/7 -efecte -benefice -ale-video -jocurilor – 10724750
[3] https://unity3d.com/games -made -with-unity
[4] https://unity.com/
[5] https://unity.com/solutions/film/animation
[6] (2020) https://www.quora.com/What -is-unity -game -engine
[7] https://docs.unity3d.com/Manual/CreatingAndUsingScripts.html
[8] https://docs.unity3d.com/Manual/ScriptingSection.html
[9]https://www.digi24.ro/stiri/sci -tech/lumea -digitala/tot -ce-trebuie -sa-stiti-despre -jocurile -video –
1-515600
[10]https://www.scritu b.com/stiinta/informatica/Istoria -calculatoarelor -person1631071824.php
[11] https://en.wikipedia.org/wiki/Video_game
54
7.Appendix
Enemy Animator
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAnimator : MonoBehaviour {
private Animator anim;
void Awake () {
anim = GetComponent<Animator>();
}
public void Walk(bool walk) {
anim.SetBool(AnimationTags.WALK_PARAMETER, walk);
}
public void Run(bool run) {
anim.SetBool(AnimationTags.RUN_PARAMETER, run);
}
public void Attack() {
anim.SetTrigger(AnimationTags.ATTACK_TRIGGER);
}
public void Dead() {
anim.SetTrigger(AnimationTags.DEAD_TRIGGER);
}
}
Enemy Audio
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAudio : MonoBehaviour {
private AudioSource audioSource;
[SerializeField]
private AudioClip scream_Clip, die_Clip;
[SerializeField]
private AudioClip[] attack_Clips;
// Use this for initialization
void Awake () {
audioSource = GetComponent<AudioSource>();
}
public void Play_ScreamSound() {
audioSource.clip = scream_Clip;
audioSource.Play();
}
public void Play_AttackSound() {
audioSource.clip = attack_Clips[Random.Range(0, attack_Clips.Length)];
audioSource.Play();
55
}
public void Play_DeadSound() {
audioSource.clip = die_Clip;
audioSource.Play();
}
}
Enemy Controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public enum EnemyState {
PATROL,
CHASE,
ATTACK
}
public class EnemyController : MonoBehaviour {
private EnemyAnimator enemy_Anim;
private NavMeshAgent navAgent;
private EnemyState enemy_State;
public float walk_Speed = 0.5f;
public float run_Speed = 4f;
public float chase_Distance = 7f;
private float current_Chase_Distance;
public float attack_Distance = 1.8f;
public float chase_After_Attack_Distance = 2f;
public float patrol_Radius_Min = 20f, patrol_Radius_Max = 60f;
public float patrol_For_This_Time = 15f;
private float patrol_Timer;
public float wait_Before_Attack = 2f;
private float attack_Timer;
private Transform target;
public GameObject attack_Point;
private EnemyAudio enemy_Audio;
void Awake() {
enemy_Anim = GetComponent<EnemyAnimator>();
navAgent = GetComponent<NavMeshAgent>();
target = GameObject.FindWithTag(Tags.PLAYER_TAG).transform;
enemy_Audio = GetComponentInChildren<EnemyAudio>();
}
// Use this for initialization
void Start () {
56
enemy_State = EnemyState.PATROL;
patrol_Timer = patrol_For_This_Time;
// when the enemy first gets to the player
// attack right away
attack_Timer = wait_Before_Attack;
// memorize the value of chase distance
// so that we can put it back
current_Chase_Distance = chase_Distance;
}
// Update is called once per frame
void Update () {
if(enemy_State == EnemyState.PATROL) {
Patrol();
}
if(enemy_State == EnemyState.CHASE) {
Chase();
}
if (enemy_State == EnemyState.ATTACK) {
Attack();
}
}
void Patrol() {
// tell nav agent that he can move
navAgent.isStopped = false;
navAgent.speed = walk_Speed;
// add to the patrol timer
patrol_Timer += Time.deltaTime;
if(patrol_Timer > patrol_For_This_Time) {
SetNewRandomDestination();
patrol_Timer = 0f;
}
if(navAgent.velocity.sqrMagnitude > 0) {
enemy_Anim.Walk( true);
} else {
enemy_Anim.Walk( false);
}
// test the distance between the player and the enemy
if(Vector3.Distance(transform.position, target.position) <= chase_Distance) {
enemy_Anim.Walk( false);
enemy_State = EnemyState.CHASE;
57
// play spotted audio
enemy_Audio.Play_ScreamSound();
}
} // patrol
void Chase() {
// enable the agent to move again
navAgent.isStopped = false;
navAgent.speed = run_Speed;
// set the player's position as the destination
// because we are chasing(running towards) the player
navAgent.SetDestination(target.position);
if (navAgent.velocity.sqrMagnitude > 0) {
enemy_Anim.Run( true);
} else {
enemy_Anim.Run( false);
}
// if the distance between enemy and player is less than attack distance
if(Vector3.Distance(transform.position, target.position) <= attack_Distance) {
// stop the animations
enemy_Anim.Run( false);
enemy_Anim.Walk( false);
enemy_State = EnemyState.ATTACK;
// reset the chase distance to previous
if(chase_Distance != current_Chase_Distance) {
chase_Distance = current_Chase_Distance;
}
} else if(Vector3. Distance(transform.position, target.position) > chase_Distance)
{
// player run away from enemy
// stop running
enemy_Anim.Run( false);
enemy_State = EnemyState.PATROL;
// reset the patrol timer so that the function
// can calculate the new patrol destination right away
patrol_Timer = patrol_For_This_Time;
// reset the chase distance to previous
if (chase_Distance != current_Chase_Distance) {
chase_Distance = current_Chase_Distance;
}
} // else
} // chase
58
void Attack() {
navAgent.velocity = Vector3.zero;
navAgent.isStopped = true;
attack_Timer += Time.deltaTime;
if(attack_Timer > wait_Before_Attack) {
enemy_Anim.Attack();
attack_Timer = 0f;
// play attack sound
enemy_Audio.Play_AttackSound();
}
if(Vector3.Distance(transform.position, target.positio n) >
attack_Distance + chase_After_Attack_Distance) {
enemy_State = EnemyState.CHASE;
}
} // attack
void SetNewRandomDestination() {
float rand_Radius = Random.Range(patrol_Radius_Min, patrol_Radius_Max) ;
Vector3 randDir = Random.insideUnitSphere * rand_Radius;
randDir += transform.position;
NavMeshHit navHit;
NavMesh.SamplePosition(randDir, out navHit, rand_Radius, -1);
navAgent.SetDestination(navHit.position);
}
void Turn_On_AttackPoint() {
attack_Point.SetActive( true);
}
void Turn_Off_AttackPoint() {
if (attack_Point.activeInHierarchy) {
attack_Point.SetActive( false);
}
}
public EnemyState Enemy_State {
get; set;
}
}
Enemy Manager
using System.Collections;
using System.Collections.Generic;
59
using UnityEngine;
public class EnemyManager : MonoBehaviour {
public static EnemyManager instance;
[SerializeField]
private GameObject cannibal_Prefab;
public Transform[] cannibal_SpawnPoints;
[SerializeField]
private int cannibal_Enemy_Count;
private int initial_Cannibal_Count;
public float wait_Before_Spawn_Enemies_Time = 10f;
// Use this for initialization
void Awake () {
MakeInstance();
}
void Start() {
initial_Cannibal_Count = cannibal_Enemy_Count;
SpawnEnemies();
StartCoroutine( "CheckToSpawnEnemies" );
}
void MakeInstance() {
if(instance == null) {
instance = this;
}
}
void SpawnEnemies() {
SpawnCannibals();
}
void SpawnCannibals() {
int index = 0;
for (int i = 0; i < cannibal_Ene my_Count; i++) {
if (index >= cannibal_SpawnPoints.Length) {
index = 0;
}
Instantiate(cannibal_Prefab, cannibal_SpawnPoints[index].position,
Quaternion.identity);
index++;
}
cannibal_Enemy_Count = 0;
}
60
IEnumerator CheckToSpawnEnemies() {
yield return new WaitForSeconds(wait_Before_Spawn_Enemies_Time);
SpawnCannibals();
StartCoroutine( "CheckToSpawnEnemies" );
}
public void EnemyDied( bool cannibal) {
if(cannibal) {
cannibal_Enemy_Count++;
if(cannibal_Enemy_Count > initial_Cannibal_Count) {
cannibal_Enemy_Count = initial_Cannibal_Count;
}
}
}
public void StopSpawning() {
StopCoroutine( "CheckToSpawnEnemies" );
}
}
TagHolder
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Axis
{
public const string HORIZONTAL = "Horizontal" ;
public const string VERTICAL = "Vertical" ;
}
public class MouseAxis
{
public const string MOUSE_X = "Mouse X" ;
public const string MOUSE_Y = "Mouse Y" ;
}
public class AnimationTags
{
public const string ZOOM_IN_ANIM = "ZoomIn" ;
public const string ZOOM_OUT_ANIM = "ZoomOut" ;
public const string SHOOT_TRIGGER = "Shoot";
public const string AIM_PARAMETER = "Aim";
public const string WALK_PARAMETER = "Walk";
public const string RUN_PARAMETER = "Run";
public const string ATTACK_TRIGGER = "Attack" ;
public const string DEAD_TRIGGER = "Dead";
}
61
public class Tags
{
public const string LOOK_ROOT = "Look Root" ;
public const string ZOOM_CAMERA = "FP Camera" ;
public const string CROSSHAIR = "Crossha ir";
public const string ARROW_TAG = "Arrow";
public const string AXE_TAG = "Axe";
public const string PLAYER_TAG = "Player" ;
public const string ENEMY_TAG = "Enemy";
}
Main Menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void QuitGame()
{
Application.Quit();
}
}
AttackScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackScript : MonoBehaviour {
public float damage = 2f;
public float radius = 1f;
public LayerMask layerMask;
void Update () {
Collider[] hits = Physics.OverlapSphere(transform.position, radius, layerMask);
if(hits.Length > 0) {
print("We touched: " + hits[0].gameObject.tag);
hits[0].game Object.GetComponent<HealthScript>().ApplyDamage(damage);
gameObject.SetActive( false);
}
}
}
62
HealthScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class HealthScript : MonoBehaviour
{
private EnemyAnimator enemy_Anim;
private NavMeshAgent navAgent;
private EnemyController enemy_Controller;
public float health = 100f;
public bool is_Player, is_Cannibal;
private bool is_Dead;
private EnemyAudio enemyAudio;
private PlayerStats player_Stats;
void Awake()
{
if (is_Cannibal)
{
enemy_Anim = GetComponent<EnemyAnimator>();
enemy_Controller = GetComponent<EnemyController>();
navAgent = GetComponent<NavMeshAgent>();
// get enemy audio
enemyAudio = GetComponentInChildren<EnemyAudio>();
}
if (is_Player)
{
player_Stats = GetComponent<PlayerStats>();
}
}
public void ApplyDamage( float damage)
{
// if we died don't execute the rest of the code
if (is_Dead)
return;
health -= damage;
if (is_Player)
{
// show the stats(display the health UI value)
player_Stats.Display_HealthStats(health);
}
if (is_Cannibal)
{
if (enemy_Controller.Enemy_State == EnemyState.PATROL)
{
enemy_Controller.chase_Distance = 50f;
63
}
}
if (health <= 0f)
{
PlayerDied();
is_Dead = true;
}
} // apply damage
void PlayerDied()
{
if (is_Cannibal)
{
GetComponent<Animator>().ena bled = false;
GetComponent<BoxCollider>().isTrigger = false;
GetComponent<Rigidbody>().AddTorque( -transform.forward * 5f);
enemy_Controller.enabled = false;
navAgent.enabled = false;
enemy_Anim.enabled = false;
StartCoroutine(DeadSound());
// EnemyManager spawn more enemies
}
if (is_Player)
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag(Tags.ENEM Y_TAG);
for (int i = 0; i < enemies.Length; i++)
{
enemies[i].GetComponent<EnemyController>().enabled = false;
}
// call enemy manager to stop spawning enemis
GetComponent<Play erMovement>().enabled = false;
GetComponent<PlayerAttack>().enabled = false;
GetComponent<WeaponManager>().GetCurrentSelectedWeapon().gameObject.SetActive( false);
}
if (tag == Tags.PLAYER_TAG)
{
Invoke("RestartGame" , 3f);
}
else
{
64
Invoke("TurnOffGameObject" , 3f);
}
} // player died
void RestartGame()
{
UnityEngine.SceneManagement.SceneManager.LoadScene( "SampleScene" );
}
void TurnOffGameObject()
{
gameObject.SetActive( false);
}
IEnumerator DeadSound()
{
yield return new WaitForSeconds(0.3f);
enemyAudio.Play_DeadSound();
}
}
MouseLook
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
[SerializeField]
private Transform playerRoot, lookRoot;
[SerializeField]
private bool invert;
[SerializeField]
private bool can_Unlock = true;
[SerializeField]
private float sensivity = 5f;
[SerializeField]
private int smooth_Steps = 10;
[SerializeField]
private float smooth_Weight = 0.4f;
[SerializeField]
private float roll_Angle = 10f;
[SerializeField]
private float roll_Speed = 3f;
[SerializeField]
private Vector2 default_Look_Limits = new Vector2( -70f, 80f);
private Vector2 look_Angles;
private Vector2 current_Mouse_Look;
private Vector2 smooth_Move;
65
private float current_Roll_Angle;
private int last_Look_Frame;
// Use this for initialization
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
LockAndUnlockCursor();
if (Cursor.lockState == CursorLockMode.Locked)
{
LookAround();
}
}
void LockAndUnlockCursor()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
} // lock and unlock
void LookAround()
{
current_Mouse_Look = new Vector2(
Input.GetAxis(MouseAxis.MOUSE_Y), Input.GetAxis(MouseAxis.MOUSE_X));
look_Angles.x += current_Mouse_Look.x * se nsivity * (invert ? 1f : -1f);
look_Angles.y += current_Mouse_Look.y * sensivity;
look_Angles.x = Mathf.Clamp(look_Angles.x, default_Look_Limits.x,
default_Look_Limits.y);
lookRoot.localRotation = Quaternion.Euler(look_Angles.x, 0 f, 0f);
66
playerRoot.localRotation = Quaternion.Euler(0f, look_Angles.y, 0f);
} // look around
}
PlayerAttack
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttack : MonoBehaviour
{
private WeaponManager weapon_Manager;
public float fireRate = 15f;
private float nextTimeToFire;
public float damage = 20f;
private Animator zoomCameraAnim;
private bool zoomed;
private Camera mainCam;
private GameObject cro sshair;
private bool is_Aiming;
[SerializeField]
private GameObject arrow_Prefab, spear_Prefab;
[SerializeField]
private Transform arrow_Bow_StartPosition;
void Awake()
{
weapon_Manager = GetComponent<WeaponManager> ();
zoomCameraAnim = transform.Find(Tags.LOOK_ROOT)
.transform.Find(Tags.ZOOM_CAMERA).GetComponent<Animator>();
crosshair = GameObject.FindWithTag(Tags.CROSSHAIR);
mainCam = Camera.main;
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
WeaponShoot();
ZoomInAndOut();
67
}
void WeaponShoot()
{
// if we have assault riffle
if (weapon_Manager.GetCurrentSelectedWeapon().fireType == WeaponFireType.MULTIPLE)
{
// if we press and hold left mouse click AND
// if Time is greater than the nextTimeToFire
if (Input.GetMouseButton(0) && Time.time > nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
weapon_Manager.GetCurrentSelectedWeapon().ShootAnimation();
BulletFired();
}
// if we ha ve a regular weapon that shoots once
}
else
{
if (Input.GetMouseButtonDown(0))
{
// handle axe
if (weapon_Manager.GetCurrentSelectedWeapon().tag == Tags.AXE_TAG)
{
weapon_Manager.GetCurrentSelectedWeapon().ShootAnimation();
}
// handle shoot
if (weapon_Manager.GetCurrentSelectedWeapon().bulletType ==
WeaponBulletType.BULLET)
{
weapon_Manager.GetCurrentSelectedWeapon().ShootAnimation();
BulletFired();
}
else
{
// we have an arrow or spear
if (is_Aiming)
{
weapon_Manager.GetCurrentSelectedWeapon().ShootAnimation();
if (weapon_Manager.GetCurrentSelectedWeapon().bulletType
== WeaponBulletType.ARROW)
{
// throw arrow
ThrowArrowOrSpear( true);
}
68
else if (weapon_Manager.GetC urrentSelectedWeapon().bulletType
== WeaponBulletType.SPEAR)
{
// throw spear
ThrowArrowOrSpear( false);
}
}
} // else
} // if input get mouse button 0
} // else
} // weapon shoot
void ZoomInAndOut()
{
// we are going to aim with our camera on the weapon
if (weapon_Manager.GetCurrentSelectedWeapon().weapon_Aim == WeaponAim.AIM)
{
// if we press and hold right mouse button
if (Input.GetMouseButtonDown(1))
{
zoomCameraAnim.Play(AnimationTags.ZOOM_IN _ANIM);
crosshair.SetActive( false);
}
// when we release the right mouse button click
if (Input.GetMouseButtonUp(1))
{
zoomCameraAnim.Play(AnimationTags.ZOOM_OUT_ANIM);
crosshair.SetActive( true);
}
} // if we need to zoom the weapon
if (weapon_Manager.GetCurrentSelectedWeapon().weapon_Aim == WeaponAim.SELF_AIM)
{
if (Input.GetMouseButtonDown(1))
{
weapon_Manager.GetCurrentSelectedWeapon().Aim( true);
is_Aiming = true;
}
if (Input.GetMouseButtonUp(1))
{
weapon_Manager.GetCurrentSelectedWeapon().Aim( false);
69
is_Aiming = false;
}
} // weapon self aim
} // zoom in and out
void ThrowArrowOrSpear( bool throwArrow)
{
if (throwArrow)
{
GameObject arrow = Instantiate(arrow_Prefab);
arrow.transform.position = arrow_Bow_StartPosition.position;
arrow.GetComponent<ArrowBowScript>().Launch(mainCam);
}
else
{
GameObject spear = Instantiate(spear_Prefab);
spear.trans form.position = arrow_Bow_StartPosition.position;
spear.GetComponent<ArrowBowScript>().Launch(mainCam);
}
} // throw arrow or spear
void BulletFired()
{
RaycastHit hit;
if (Physics.Raycast(mainCam.transform.position, mainCam.transform.forward, out
hit))
{
if (hit.transform.tag == Tags.ENEMY_TAG)
{
hit.transform.GetComponent<HealthScript>().ApplyDamage(damage);
}
}
} // bullet fired
}
PlayerAxeWooshSound
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAxeWooshSound : MonoBehaviour {
[SerializeField]
private AudioSource audioSource;
70
[SerializeField]
private AudioClip[] woosh_Sounds;
void PlayWooshSound() {
audioSource.clip = woosh_Sounds[Random.Range(0, woosh_Sounds.Length)];
audioSource.Play();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerFootsteps : MonoBehaviour
{
private AudioSource footstep_Sound;
[SerializeField]
private AudioClip[] footstep_Clip;
private CharacterController character_Controller;
[HideInInspector]
public float volume_Min, volume_Max;
private float accumulated_Distance;
[HideInInspector]
public float step_Distance;
void Awake()
{
footstep_Sound = GetComponent<AudioSource>();
character_Controller = GetComponentInParent<CharacterController>();
}
void Update()
{
CheckToPlayFootstepSound();
}
void CheckToPlayFootstepSound()
{
// if we are NOT on the ground
if (!character_C ontroller.isGrounded)
return;
if (character_Controller.velocity.sqrMagnitude > 0)
{
// accumulated distance is the value how far can we go
// e.g. make a step or sprint, or move while crouching
// until we play the footstep sound
accumulated_Distance += Time.deltaTime;
if (accumulated_Distance > step_Distance)
{
71
footstep_Sound.volume = Random.Range(volume_Min, volume_Max);
footstep_Sound.clip = footstep_Clip[Random.Range(0,
footstep_Clip.Length)];
footstep_Sound.Play();
accumulated_Distance = 0f;
}
}
else
{
accumulated_Distance = 0f;
}
}
}
PlayerMovement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private CharacterController character_Controller;
private Vector3 move_Direction;
public float speed = 5f;
private float gravity = 20f;
public float jump_Force = 10f;
private float vertical_Velocity;
void Awake()
{
character_Controller = GetComponent<CharacterController>();
}
void Update()
{
MoveThePlayer();
}
void MoveThePlayer()
{
move_Direction = new Vector3(Input.GetAxis(Axis.HORIZONTAL), 0f,
Input.GetAxis(Axis.VERTICAL));
move_Direction = transform.TransformDirection(move_Direction);
move_Direction *= speed * Time.deltaTime;
ApplyGravity();
character_Controller.Move(move_Direction);
72
} // move player
void ApplyGravity()
{
vertical_Velocity -= gravity * Time.deltaTime;
// jump
PlayerJump();
move_Direction.y = vertical_Velocity * Time.deltaTime;
} // apply gravity
void PlayerJump()
{
if (character_Controller.isGrounded && Input.GetKeyDown(KeyCode.Space))
{
vertical_Velocity = jump_Force;
}
}
}
PlayerSprintAndCrouch
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSprintAndCrouch : MonoBeh aviour
{
private PlayerMovement playerMovement;
public float sprint_Speed = 10f;
public float move_Speed = 5f;
public float crouch_Speed = 2f;
private Transform look_Root;
private float stand_Height = 1.6f;
private float crouch_Height = 1f;
private bool is_Crouching;
private PlayerFootsteps player_Footsteps;
private float sprint_Volume = 1f;
private float crouch_Volume = 0.1f;
private float walk_Volume_Min = 0.2f, walk_Volume_Max = 0.6f;
private float walk_Step_Distance = 0.4f;
private float sprint_Step_Distance = 0.25f;
private float crouch_Step_Distance = 0.5f;
private PlayerStats player_Stats;
private float sprint_Value = 100f;
public float sprint_Treshold = 10f;
void Awake()
73
{
playerMovement = GetComponent<PlayerMovement>();
look_Root = transform.GetChild(0);
player_Footsteps = GetComponentInChildren<PlayerFootsteps>();
player_Stats = GetComponent<PlayerStats>();
}
void Start()
{
player_Footsteps.volume_Min = walk_Volume_Min;
player_Footsteps.volume_Max = walk_Volume_Max;
player_Footsteps.step_Distance = walk_Step_Distance;
}
// Update is called once per frame
void Update()
{
Sprint();
Crouch();
}
void Sprint()
{
// if we have stamina we can sprint
if (sprint_Value > 0f)
{
if (Input.GetKeyDown(KeyCode.LeftShift) && !is_Crouching)
{
playerMovement.speed = sprint_Speed;
player_Footsteps.step_Distance = sprint_Step_Distance;
player_Footsteps.volume_Min = sprint_Volume;
player_Footsteps.volume_Max = sprint_Volume;
}
}
if (Input.GetKeyUp(KeyCode.LeftShift) && !is_Crouching)
{
playerMovement.speed = move_Speed;
player_Footsteps.step_Distance = walk_Step_Distance;
player_Footsteps.volume_Min = walk_Volume_Min;
player_Footsteps.volume_Max = walk_Volume_Max;
}
if (Input.GetKey(KeyCode.LeftShift) && !is_Crouching)
{
sprint_Value -= sprint_Treshold * Time.de ltaTime;
if (sprint_Value <= 0f)
{
74
sprint_Value = 0f;
// reset the speed and sound
playerMovement.speed = move_Speed;
player_Footsteps.step_Distance = walk_Step_Distance;
player_Footsteps.volume_Min = walk_Volume_Min;
player_Footsteps.volume_Max = walk_Volume_Max;
}
player_Stats.Display_StaminaStat s(sprint_Value);
}
else
{
if (sprint_Value != 100f)
{
sprint_Value += (sprint_Treshold / 2f) * Time.deltaTime;
player_Stats.Display_StaminaStats(sprint_Value);
if (sprint_Value > 100f)
{
sprint_Value = 100f;
}
}
}
} // sprint
void Crouch()
{
if (Input.GetKeyDown(KeyCode.C))
{
// if we are crouching – stand up
if (is_Crouching)
{
look_Root.localPosition = new Vector3(0f, stand_Height, 0f);
playerMovement.speed = move_Speed;
player_Footsteps.step_Distance = walk_Step_Di stance;
player_Footsteps.volume_Min = walk_Volume_Min;
player_Footsteps.volume_Max = walk_Volume_Max;
is_Crouching = false;
}
else
{
// if we are not crouching – crouch
look_Root.localPosition = new Vector3(0f, crouch_Height, 0f);
playerMovement.speed = crouch_Speed;
player_Footsteps.step_Distance = crouch_Step_Distance;
75
player_Footsteps. volume_Min = crouch_Volume;
player_Footsteps.volume_Max = crouch_Volume;
is_Crouching = true;
}
} // if we press c
} // crouch
}
PlayerStats
using System.Collections;
using System.Collections. Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerStats : MonoBehaviour {
[SerializeField]
private Image health_Stats, stamina_Stats;
public void Display_HealthStats( float healthValue) {
healthValue /= 100f;
health_Stats.fillAmount = healthValue;
}
public void Display_StaminaStats( float staminaValue) {
staminaValue /= 100f;
stamina_Stats.fillAmount = staminaValue;
}
}
ArrowBowScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowBowScript : MonoBehaviour
{
private Rigidbody myBody;
public float speed = 30f;
public float deactivate_Timer = 3f;
public float damage = 50f;
void Awake()
{
76
myBody = GetComponent<Rigidbody>();
}
// Use this for initialization
void Start()
{
Invoke("DeactivateGameObject" , deactivate_Timer);
}
public void Launch(Camera mainCamera)
{
myBody.velocity = mainCamera.transform.forward * speed;
transform.LookAt(transform.position + myBody.velocity);
}
void DeactivateGameObject()
{
if (gameObject.activeInHierarchy)
{
gameObject.SetAct ive(false);
}
}
void OnTriggerEnter(Collider target)
{
// after we touch an enemy deactivate game object
if (target.tag == Tags.ENEMY_TAG)
{
target.GetComponent<HealthScript>().ApplyDamage(damage);
gameObject.SetActive( false);
}
}
}
WeaponHandler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum WeaponAim
{
NONE,
SELF_AIM,
AIM
}
public enum WeaponFireType
{
SINGLE,
MULTIPLE
}
public enum WeaponBulletType
{
77
BULLET,
ARROW,
SPEAR,
NONE
}
public class WeaponHandler : MonoBehaviour
{
private Animator anim;
public WeaponAim weapon_Aim;
[SerializeField]
private GameObject muzzleFlash;
[SerializeField]
private AudioSource shootSound, reload_Sound;
public WeaponFireType fireType;
public WeaponBulletType bulletType;
public GameObject attack_Point;
void Awake()
{
anim = GetCo mponent<Animator>();
}
public void ShootAnimation()
{
anim.SetTrigger(AnimationTags.SHOOT_TRIGGER);
}
public void Aim(bool canAim)
{
anim.SetBool(AnimationTags.AIM_PARAMETER, canAim);
}
void Turn_On_MuzzleFlash()
{
muzzleFlash.SetActive( true);
}
void Turn_Off_MuzzleFlash()
{
muzzleFlash.SetActive( false);
}
void Play_ShootSound()
{
shootSound.Play();
}
void Play_ReloadSound()
{
reload_Sound.Play();
}
void Turn_On_AttackPoint()
{
attack_Point.SetActive( true);
}
78
void Turn_Off_AttackPoint()
{
if (attack_Point.activeInHierarchy)
{
attack_Point.SetActive( false);
}
}
}
WeaponManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
[SerializeField]
private WeaponHandler[] weapons;
private int current_Weapon_Index;
// Use this for initialization
void Start()
{
current_Weapon_Index = 0;
weapons[current_Weapon_Index].gameObject.SetActive( true);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
TurnOnSelectedWeapon(0);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
TurnOnSelectedWeapon(1);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
TurnOnSelectedWeapon(2);
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
TurnOnSelectedWeapon(3);
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{
TurnOnSelectedWeapon(4);
}
if (Input.GetKeyDown(KeyCode.Alpha6))
{
TurnOnSelectedWeapon(5);
79
}
} // update
void TurnOnSelectedWeapon( int weaponIndex)
{
if (current_Weapon_Index == weaponIndex)
return;
// turn of the current weapon
weapons[current_Weapon_Index].gameObject.SetActive( false);
// turn on the selected weapon
weapons[weaponIndex].gameObject.SetActive( true);
// store the current selected weapon index
current_Weapon_Index = weaponIndex;
}
public WeaponHandler GetCurrentSelectedWeapon()
{
return weapons[current_Weapon_Index];
}
}
Copyright Notice
© Licențiada.org respectă drepturile de proprietate intelectuală și așteaptă ca toți utilizatorii să facă același lucru. Dacă consideri că un conținut de pe site încalcă drepturile tale de autor, te rugăm să trimiți o notificare DMCA.
Acest articol: Rezumat în limba română … … … … 5 [623922] (ID: 623922)
Dacă considerați că acest conținut vă încalcă drepturile de autor, vă rugăm să depuneți o cerere pe pagina noastră Copyright Takedown.
