Add the “ExperienceManager.cs/.js” script in your scene (It is recommended that the object including this and all other main scripts is a child object of the main player object):
1) Player: Main player object.
2) Spells: Covered later in this section.
3) Spell Cast Reload: Time needed between casting different spells.
4) Enable Targeting Enemies: If checked, this will require the player to select an enemy before casting a spell that can do damage. If the spell isn’t supposed to do damage to enemies, then selecting a target is not required to cast it.
5) Audio Source Object.
6) Animation Controller Object.
The spell book displays all the spells (icon+description for each spell) and allows the player to drag and drop spells to the spell bar to use them. To display a spell in the spell book, you need to associate it with one of the spell book slots which will be covered later in this this section.
1) Spell Book Key: Key used to show/hide the spell book panel.
2) Is Movable: If checked, the player can drag the spell book panel and place it anywhere in the screen.
3) Drag Panel Slot: To drag the spell book panel’s panel smoothly, you need to create an empty UI element (contains a Rect Transform only) and make it very small and place it as a child object of the UI canvas then put it in this field.
4) UI Canavs Transform: Drag and drop the canvas object that contains the spell book panel.
5) Panel Transform: Drag and drop the spell book’s panel here. The spell book panel object should include an Image component with the spell book’s backdrop sprite on it. It must also have the Graphics Raycaster component and an Event Trigger. The Event Trigger must include two types of events:
– Begin Drag event: Drag and drop the object that holds the Spell Manager script and pick “SpellManager -> DragStarted()”.
– End Drag event: Drag and drop the object that holds the Spell Manager script and pick “SpellManager -> DragEnded()”.
6) Drag Slot: Create a child UI object of the spell book UI panel and add an Image component to it. Preferably, the size of this object should match the spell slot’s size.
7) Creating Spell Book Slots:
For each spell book slot, create a new UI element, place it as a child object of the spell book UI panel and add an Image component to it. Then add the “SpellSlot” script to this object with the “Spell Book Slot” bool only checked to true. Then add an Event Trigger with the current events:
– Begin Drag event: Drag and drop the spell book slot object and select: “SpellSlot -> StartDragging()”.
– End Drag event: Drag and drop the spell book slot object and select: “SpellSlot-> StopDragging()”.