Weapon Spawner is a template that spawns a weapon item for the player to equip.
The template uses inventory items for each weapon and stores them in a data table. The spawner can use a random or specific index from the data table. It will also respawn a new weapon once a player equips a weapon from the spawner.
This template works with the Weapon Switcher template.
Note
If the Dependent folders are empty in Project Content under Imported Content for this component, save and reload the project to fix it.
Setup
Drag and drop the Weapon Spawner template into the Hierarchy.
Preview the project and interact with the spawner to equip a weapon.
How to Use
Custom Properties
The root object of the template has 4 custom properties.
- Weapons Data
A data table with all the available weapon items that can be spawned.
- Use Custom Weapon Index
If true, it will use a specific index in the weapons data table to spawn. If false, it will choose a random weapon from the data table.
- Custom Weapon Index
The specific weapon index to use, if Use Custom Weapon Index is active.
- Spawn Interval Duration
The amount of seconds to delay for spawning a new weapon after the player equips a weapon from the spawner.
Creating a Weapon Item
- Create a new template for the weapon equipment.
- In Project Content window, create a new item asset.
- Assign it a name and select the item asset to see its Properties.
- Drag and drop the weapon equipment template into the Item Template property.
- Add 3 custom properties to the Item Asset.
- Name: “Slot”, Type: Int, The slot number that this weapon will occupy when equipped.
- Name: “Icon”, Type: Asset Reference, The 2d icon that will display on the UI.
- Name: “Ammo”, Type: Int, A reference for the amount of ammo which should equal the starting ammo. Do not add if ammo is not required (sword for example).
- Right click the Ammo custom property, and select the Enable Dynamic Property option.
- Open the Weapons Spawner Data data table and drag the Item Asset into one of the rows.