DK2D Log #14 Adding A Sword To The Player
Before moving onto more stats, or loot such as gold, I thought it would be a good idea to give the player their first weapon, a sword…
DK2D Log #14 Adding A Sword To The Player
Before moving onto more stats, or loot such as gold, I thought it would be a good idea to give the player their first weapon, a sword. There are a few points of this to make it all work nicely, first of all would be to create the actual sword. For prototyping, I will just make this a square sprite and I’ll elongate it to a rectangle with a box collider set as a trigger.

To make it a little “flashier” for now, I’ll add a little particle trail effect to it as well.
Next for the basic attack, I will add a little animation of swinging the sword back and forth.
Next I will add the script for the sword I’ll just call PlayerSword. In the script for now, I will just add a public method for disabling the sword.

This method I will use in the animation, where at the end of the animation I will add an event that will trigger the method to disable the sword.
In my player controls, I will now add a new action button that will activate the sword. In my InputControls script, I will add the control for the sword attack and the sword attack method that will simply enable the sword if its disabled.


Now I have a sword that I can swing around.
메타데이터
- post_id
- bbd2c41fd9f5
- slug
- dk2d-log-14-adding-a-sword-to-the-player-bbd2c41fd9f5
- url
- https://medium.com/@eclipsek24/dk2d-log-14-adding-a-sword-to-the-player-bbd2c41fd9f5
- canonical_url
- https://medium.com/@eclipsek24/dk2d-log-14-adding-a-sword-to-the-player-bbd2c41fd9f5
- author_url
- https://medium.com/@eclipsek24
- status
- ok
- fetched_at
- 2026-06-26 21:52:29