Here you will find the description of all the modules of Kill The Dragon
Ladders are composed by a “OnTriggerEnter()” that affects the player (via tag check).
They call: Player.instance.climb.AttachToLadder(this);
so they attach themselves to the Player_Climb script.
They have a START and END point, a trigger collider on all the ladder’s lenght and they have a “consumeStaminaOverSecond” value that can be used, for example, on horizontal ladders, where the Player hungs vertically and so it’s more difficult to use.
There are 2 Prefabs of Ladders in the game. One is a normal ladder and it has a Help Plaftorm (GameObject) to let the player climb up when finishing using it. It’s a invisible collider where the player lands when it climbs up. The other prefab is Ladder (Pipe) that acts like a horizzontal ladder and consumes stamina over-time.
Script that has all the debug functions inside of it. For now it acts as a Debug.Log so it’s a collection of logs. The function is GameDebug.Log(message,subject). The subject is an enum like: Magic, Divine, Wizardry, Ranged etc. called by various scripts. All logs should use this instead of Debug.Log
Used mainly to hide Renderers that are visible in Editor but are there only for debug purposes. Like the “Help Platform” of the Ladders, or their Trigger Colliders.
- Buffs Hud
UI for the Player_Buffs composed by Hud_Buffs.cs and Hud_BuffIcon.cs
Hud_Buffs is the Manager that simply checks if in Player_Buffs there are “Buffs” in the list. cycle through all the Hud_BuffIcon, and assign those buffs as value to Hud_BuffIcon via public Buff attachedBuff.
Or, give the null value and deactivate the unused icons (set.Active=false).
Top left Buff icons. They are inside a Vertical Layout group.
The Hud_BuffIcon automatically sets the icon image (sprite) based on the attachedBuff and then it lerps from 0 to 1 the “Fill.amount” of an Image, the “circular timer”, based on the “duration / startingDuration” value of the buff.
- Experience Bar Hud
This script controls the bottom experience bar of the player.
If player level is capped the bar is useless so it will get removed (setActive=false). If the player is ready to level up the bar is filled and the color is changed ( Violet ).
The algorithm works in this way:
First calculate the Full range of exp from previous level to next level
( next level xp – previous level xp)
Then calculate the earned exp this level
( total xp – previous level xp )
Then divide earned xp / full range.
- Vital Bars Hud
The bottom left mana/health/stamina bars UIs.
Composed by Hud_PlayerVitals and Hud_SliderbarCriticalBlink.
Hud_PlayerVitals controls the UI bars (slider) of Health, Mana and Stamina ( called vitals ).
This script simply set the fill amount of the UI.Sliders with value/maxValue from the respective vitals scripts.
Hud_SliderbarCriticalBlink instead does this: When fill.value is less than 20%, it will blink the background, because it’s considered a critical low value for the bar.
Class that compose all the items. The items are found in the Items List GameObject. The items have a unique ID that is assigned by Items_list script in the beginning (Awake), then name, icon, description, Item.Type etc. This is the list of all Item types.
misc, helm, armour, gauntlet, leg, necklace, ring, mainhand, offhand, projectile,
Also, inside the Items there is Item Bonus: Player_Bonus that is the main class that compose all the possible bonus that the player can get from everything (equipments, buffs, levels etc.)
Example: Mana regeneration, Maximum stamina Bonus, Maximum Health bonus etc…
If the item has a Buff Duration > 0 and is a “Misc” typology of object, it can be used as a Buff ( Let’s think about a consumable potion/scroll etc.) by clicking on the use button in the inventory
This class compose the Items list, accessible by instance, with GetComponentsInChildren in the void Awake(). It gives a ID to all items based by the order it finds them. Usually is the same order on which they are located into the gameObject (Items List) from 0 to x.
This script handles the Items Descriptor (inspector) window to identify the items bonuses, the name, the description etc. It’s a detailed window regarding any item. Can be called via instance by passing as value a Item ID. It will show the GUI of this item descriptor, and will fill it with the item details. Can be called by pressing the magnifier button of any item label in the inventory, or by pressing Shift + E when collecting a dropped item.
Script that handles the drop of a item on the ground. With this script you can spawn a “Dropped Item” by passing the coordinates and the item ID.
There are 2 functions. One to spawn by passing the Vector3 position SpawnItemAtPosition(Vector3 position, int itemID), and the second directly drops the item from the “main” player camera DropItemFromPlayer(int itemID).
It instantiates a Items_ItemDropped baseItem (prefab) and then it passes the variables with .Setup(itemID, position); Items_ItemDropped will handle everything else.
This is attached to the dropped items that fall on the ground. Can be found on the base prefab called Dropped Item Base that is cloned to generated all the dropped items.
Once the variables are set via .Setup(itemID, position) from Items_Dropper, this script has OnTriggerEnter() onTriggerExit() and via a tag check (tag==”Player”) will add/remove itself to the list of Items_Grabber (example: Items_Grabber.instance.AddItem(this) ). If inside this list, the item is considered in-range of the player and can be grabbed. Also dropped items have a self destruction timer when they are not taken for some time. OnDisable() it also remove itself out of the list.
Also, those dropped items have a Outline component via the package QuickOutline that adds an outline to Mesh Renderers. This outline is enabled/disabled by Items_Grabber specifically enabled on the “mostLookedItem”
The label on the top of the Dropped items (when you look at them)
This script, called by instance from Items_Grabber sets a tooltip label on the top of a dropped item (Items_ItemDropped) with name/icon of the corresponding item. Specifically it is on the top of the “mostLookedItem”. It also resize itself based on the lenght of the text name and other parameters like paddings etc.
The items (type of Items_ItemDropped) contained in the list of this script public List< Items_ItemDropped> grabbableItems are considered close enough to be picked up. They entered inside the list by OnTriggerEnter(). If they are far away or destroyed/picked up, they get automatically removed from the list. (OnTriggerExit(), OnDisable())
Also control the outline of this items. The most looked item is outlined and will have the Items_DropLabel on top of them. As mostLookedItem we intend the item that is in line of sight of the player camera (most central item on the screen).
For calculating the most looked item the formula is:
(dot product between camera and item) – (distance between camera and item).
We don’t need the distance of the dot product. just the orientation.
So, the most looked item has a value closer to 0 (all values are negative).
This is the actual script that let the player pick up by pressing E the mostLookedItem. It checks if the bool return True Inventory.instance.AddItem(itemId) < this returns a Bool.
Generally it return False when the Inventory (Inventory_Equipments) of that item type (armour, helm, misc etc) is Full.
Also, if you press E + Shift, instead, you will open the Items_Descriptor
The inventory in the game is composed by multiple inventories for each Item.Type. Those inventories are called : Inventory_Equipments. This script, first of all, contains the list of all those inventories.
Also has a collection of various functions regarding items, for example:
public bool AddItem(int id) public void EquipItem(int index) public void DropItem(int index) public void ConsumeItemAsBuff(int index, Item item) public void MoveItemUp(int index) public void MoveItemDown(int index)
public static Inventory_Equipments findInventory(Item.Type type) public static Inventory_Equipments findCurrentOpenInventory public static Inventory_Item findEquippedItem(Item.Type type)
Script used to find all the bonuses from all the equipped items.
public static Player_Bonus GetBonuses() is the function that merges all the Player_Bonus contained in the equipped items. The equipped items, for every inventory, are the ones on index 0 (except for misc inventory that has no equipped items because contains all the potions, scrolls etc.)
This class represents an inventory of a specific Item.Type max inventory size, due the nature of the game should be 5 except for the “misc” inventory. Inside this script we have the actual functions (low level) that move the items on different indexes, or remove/add them from the list. The Inventory script points at this when does functions like removing/adding items etc.
The inventories have those items inside, not the actual Item but a “link” to the actual item. They both have the ID and the connected Item retrieved from the Items_List
Script that handles the saving and loading of the Inventory_Items in every Inventory_Equipments.
In the void Start() it loads the string of all the items IDs separated by comma from Save_System.instance.saveFile.items. Then it splits the string and add back all the items into the inventory with Inventory.instance.add(Id). The Inventory script will automatically sort them in the correct Inventory_Equipments. In the void Update() it does the inverted process: it takes all the items from all the inventories, and create a string with the IDs separated by comma, then overwrite the string in Save_System.instance.saveFile.items. Example of a items string: 0,5,2,5,1,1,5,6,8,2,
This script controls the swap between melee and ranged modules by pressing Q or Scrollwheel. It simply activates the GameObject relative to the selected module and deactivate the other GameObject in array GameObject modules.
Also, when swapping modules this script is called. It is a Animation. This script stores in the void Start() the position where the entire modules parent gameObject should be (GO physicalModulesContainer). So it moves from animationStartingLocalPosition to startingLocalPosition with a lerp co-routine.
This script controls the activation of the Bow and Shield modules based on the presence of such items into the Inventory_Equipment (offHand/projectile). Example:
If you have no Bow equipped the ranged_module is not active.
If you have no Shield equipped the shield_module is not active.
Unique thing that is permanent is the sword otherwise player can’t fight.
There are 2 inventory screens in the game. One is the base menu ( where you find misc items and the icons of all equipped items )
And the second screen is the inventory of each equipment type.
helm, armour, gauntlet, leg, necklace, ring, mainhand, offhand, projectile,
The content (the item slots) of those menus changes based on the “currentInventorySelected” variable in InventoryGUI
Class that handles the Open/Close of the whole Inventory Canvas by pressing the “I” button.
Also, when clicking on the top buttons (InventoryGUI_TopButtons) to select different inventories, it opens the corresponding canvas via SelectItemsInventory(int type).
The type 0 is the “misc” items menu ( Base Menu gameObject) and the others numbers is the Equipments Menu gameObject (The inventories for each Item.Type except misc). By the way, for Equipments Menu, the screen is always the same but it changes the content of the slots inside based on currentInventorySelected. So, for example, if we click the InventoryGUI_TopButtons “Helms“, it will open Equipments Menu gameObject, and the 5 slots inside the GUI will show the corresponding 5 items into the Inventory_Equipments of Helms. This procedure is handled in the void Update() of InventoryGUI_ItemSlots_Manager.
It will store currentInventorySelected ( that is the Item.Type ) or also selectedEquipmentIndex that is the same thing but with int index.
The script that controls all the items slots inside all the inventory screens (misc, and the others). It has a connectedInventoryItem.
Inside this we will have also buttons for item actions like equip, drop, inspect etc. Those “functions buttons” are visible only if there’s a connected item inside because the compound of those mini-buttons is deactivated if the connectedInventoryItem is null. The connectedInventoryItem will be set by InventoryGUI_ItemButtons_Manager in a for cycle in void Update()
used for the Base Menu (misc items) and for the Equipments Menu(all the others). This script first of all finds the InventoryGUI_ItemSlot in children. This is the base itemSlot to duplicate. Then set the size of the array  itemSlots based on the variable inventorySize. So it fills the array with duplicated itemSlots (plus the base one at index 0).
Then, in void Update(), cycle for all the slots, and if there’s a item in Inventory.findCurrentOpenInventory.inventoryItems.Count it assign the connectedInventoryItem with the same index of the found item in the cycle for();
This script act as a manager and controls only the graphics of all the top buttons of the inventory. ( It changes the sprite to be lit/colored to greyed out) based on the variable selectedEquipmentIndex of InventoryGUI. The button click function is inside those buttons and they point to InventoryGUI.SelectItemsInventory(int type). This script is attached only on their parent (Top Buttons Container gameObject).
InventoryGUI: Base Menu
This script controls the graphics of the EquipIcons in the Base Menu (inventory) gameObject.
They have a variable with Item.Type so they find the equipped item of that type and assign the graphics.
This script is for the Misc items Inventory in the Base Menu (inventory).
It retrieves the Misc Inventory (Inventory_Equipment) then it sets the scrollContent.sizeDelta of the Scroll View according with the size of the first itemSlot found in child:
plus other variables for padding.
Also it retrieves the VerticalLayoutGroup and sets it’s “spacing” by yButtonDistance variable.
InventoryGUI: Full Label
When Inventory public bool AddItem(int id) is called, it will return “false” if the specific inventory is full. So it will call the void inside this script TriggerAnimation(string inventoryType). It will change the text string with (inventoryType + “s Inventory Full”).ToUpper() and adjust the size of the background accordingly with the size of the text.
This class first of all shows the message “Press E to talk” called talk message. The talk message is assigned by the NPC. (Every NPC has one talk message variable). Also, it stores the variable currentNpc inside if there’s a active npc nearby.
This class has the variable for npc name/tag. Also:
This class has as virtual void OnActivate(), onDeactivate() and onUse(); The void is virtual because should be overridden by the other script type of NPC.
– virtual OnActivate() is set by OnTriggerEnter() and sets currentNpc=this variable to the NPC_Manager.
– virtual OnUse() is called when you press the talk button and you’re in range, and also when the curreNpc==this.
– virtual OnDeactivate() is called when you go away (OnTriggerExit()) or when you press the ESC Key, and set currentNpc=null
Those scripts override the functions of the NPC class. They control the specific actions for every different kind of NPC
Class that controls the NPC needed to level up.
OnUse() activates the level up screen (Player_Experience.instance.readyToLevelup == true)
or it activates the levelUpExplanationScreen if not ready to level up where it explains to return back when the player is ready to level up.
Also, it deactivates, if both of the screens are not active.
NPC: Name Tag
Script that controls the name and tag (text under the name) of the NPCs.
It is called by NPC in void Start() with GetComponentInChild<Npc_NameTag>() and then via SetTags(Npc_Name, Npc_Tag); It controls the orientation of the 3Dtext and also the fade. If it’s too close the text will fade out, also if it’s too far. It’s visible only in a certain range.
This is the script that has all the variables the game needs to be Saved/Loaded. The variables will be loaded by various scripts in void Start(); // check by Find All Reference from Visual studio.
To be saved, every X seconds the Save_System will save all those variables in the respective player prefs. In the void Awake() the Save_System will load everything.
This script has an auto saving system that just calls void Save() on the Save_File (saveFile variable).
In the void Awake() it calls Load();
Every script that needs to Save stuff needs to overwrite the variables in Save_System.instance.saveFile.variable = xxxx ( can do even in void Update() ) but the actual saving in the player prefs is handled by the Save_File in a IEnumerator Routine (To avoid file corruption).
Instead, to Load the variables, all the scripts should call in void Start():
Var xxx = Save_System.instance.saveFile.variable.
Why calling in void Start()? because in void Awake() the variables are Loaded from the player prefs to the saveFile from this script.
Changes the UI.Text color inside a UI.Button if the button is uninteractable ( for example you can grey-out the text )
Called by various buttons (All the Inventory_Slot buttons) with EventTrigger : PointerEnter/PointerExit
It show a Tooltip box on mousePosition. It automatically changes bg size based on the text.
Screens: Level Up
First of all it duplicates the Screen_PlayerLevelUp_LVLBtns for every possible class in game (Taken from Player_Levels.instance.classes )
Then, by clicking on one of those buttons, it sets the “currentSelectedClass” variable. The confirmButton of this screen that let the player level up is interactable if the currentSelectedClass != -1 (something has been selected ). If you click the confirmButton
you do this: Player_LevelUp.instance.LevelUp(currentSelectedClass);
This script is on the buttons of the classes that you can level up in the Level Up Screen and it controls only the graphics.
It shows the levels unlocked in the corresponding classes.
Check if the button is the one clicked via:
isSelected = (classId == Screen_PlayerLevelUp.instance.currentSelectedClass);
So, if isSelected, this script adds +1 on the number of the levels unlocked in this class ( just a graphical change that let’s you see which level you will arrive in that class if you accept the level up) and changes the color of the icon background based on the heroClass.classColor.
Script to call via instance whenever you want to add/create a new Buff ( Can be added also from a Item if the item as a buffDuration>0).
It contains the list of all the Buffs and it decrease their duration by Time.deltaTime.
It cycle through the list of all the buffs, and if a buff is expired it adds it to a temporary list.
After the cycle, the ones in the temp list are subtracted from the original list.
If the buffs are not expired instead, merge all the Player_Bonus of all the Buffs, in a variable called allBuffBonuses.
Base class that contains all the variables of a buff. Most importantly the Player_Bonus and the buff duration. Also as a Icon (Sprite) used when you show it in Buffs Hud
Script to call when you want to unlock the cursor on the screen ( and make it visible ) or lock the player camera rotation ( when using the sword ).
For instance, in a GUI screen you need to call in void Update() CursorLock.UnlockForGUI()
The bool are lockPlayerView and unlockCursor
Player is the script that generate and add automatically all the fundamental components for the player functioning like:
GenerateBody() GenerateMovement() GenerateLife()
It takes some parameters from Player_BaseStats that are different stats just for the generation (like base health/mana/climb speed etc).
Also adds CursoLock as component. Also acts as a instance that can be called from anywhere to access those components.
A collection of very basic stats for the player mostly used for its creation. Like how tall is the player, what is the base health etc.
A script that sums all the Player_Bonus from all the things that can add bonus/malus to the player. Specifically from class levels, from equipments and from buffs. Works in a co-routine that checks every frame.