Samurai Defense is a 2D action-strategy mobile game developed in Unity.
- Engine: Unity (2D)
- Language: C#
- Input: Unity New Input System
The project features a complete and polished core game loop: Tutorial -> 5-Level Campaign with progressive difficulty and content -> Upgrades Shop (Dojo) -> Final Boss Battle -> Cinematic Credits Scene and New Game option.
- New Input System: Full implementation of Unity's modern input system.
- Movement: The character (Samurai) moves from left to right using a keyboard (WASD/Arrows) or Gamepad.
- Code Logic: Modified the
SamuraiControl.csscript to handle player inputs and character states. - Sprites & Physics: Imported the Samurai sprites and adjusted the Box Colliders and ground boundaries to ensure the character walks properly on the terrain.
- Animation System: Implemented Idle and Run states managed by the
Walkingboolean in the Animator. - Basic Combat System: Integrated the sword slash animation and configured transition arrows. Implemented code logic to "freeze" the character's movement while attacking.
- Camera: Created the
CamaraMovements.csscript for a Smooth Follow camera.
In this phase, actual combat was defined. The game evolved from manual controls to a smart "Auto-Battler" system, and visual feedback systems (health bars, damage) were integrated.
- Cooldowns: Fixed the "Double Attack" bug by implementing wait times.
- Multi-Hit: Used lists to prevent a single attack from damaging multiple enemies multiple times in a single frame.
- Pivots: Adjusted sprites to "Bottom Center" to fix visual jumping during animations.
- Automation: Manual attacking was removed. The Samurai now manages combat autonomously:
- Priority 1 (Short Range): If it detects an enemy at close range -> Sword.
- Priority 2 (Long Range): If no one is close, it checks long range -> Bow.
- Auto-Aiming (Trigonometry): Implemented
Mathf.Atan2so arrows calculate the exact trajectory towards the enemy's chest, compensating for height differences. - Action Locking: The character only attacks if standing still and the enemy is truly in front of them (dot product), preventing "sliding" across the floor.
- Improved Sensors: Zombies use a filtered
OverlapCircleAllto ignore the player's sensors (like the attack hitbox) and only stop at the physical body. - Health Bars (World Space UI): Each enemy has its own floating health bar that moves with it.
- Horde Physics: Adjusted the Collision Matrix so enemies overlap with each other (preventing chaotic pushing) but still collide with the player.
- Sacred Tower: Defendable object with a health system and Sprite swapping (destruction) upon falling.
- Target Logic: Enemies identify the tower as a priority target.
In this phase, the action prototype was transformed into a full strategy game, adding resource management, allied units, and game structure.
- Wave System: Configurable
GeneradorEnemigosscript with wave lists (number of zombies and spawn times). - Victory Logic: Implemented
WaitUntilto wait for the last enemy to die before declaring victory. - Scene Flow: Created Main Menu, Game screen, and Victory/Defeat panels with level reset functionality.
- Coin System: Enemies drop money upon death.
- UI: Real-time coin counter.
- Summoning: UI button to buy allies (Farmers) if the player has enough balance.
- Ally AI: Created the
GranjeroIAscript, which detects zombies and fights in melee combat. - Interaction: Zombies now recognize allies as valid targets and attack them.
- Health Bars: Implemented floating UI (World Space) for allies as well.
- Logic Fixes: Fixed "shooting at corpses" issues (checking
estaMuertobefore attacking) and death physics (disabling gravity).
- Sound Effects (SFX): Integrated audio for sword slashes and arrow shots.
- Music (BGM): Distinct audio tracks for the Menu and Battle.
- Dramatic Silence: Logic in the
GameManagerto stop the music upon winning or losing.
In this phase, strategic depth was added by introducing ranged units and flying "kamikaze" enemies, forcing the player to better manage their defenses.
- State Machine: Implemented
Run↔Idle↔Attacklogic. The unit stops automatically when detecting enemies, shoots, and moves forward again. - Animation Events: A professional solution for shooting. Animation Events were implemented to instantiate the arrow on the exact frame of the animation.
- Projectile Physics: Calculated rotation and direction so arrows fly toward the target.
- Flying Unit: An enemy that ignores collisions with other ground units.
- Suicidal Behavior: Basic AI that moves straight toward the target and deals immediate damage upon impact, destroying itself in the process.
- Counterplay: Introduces the actual need to use Archers to shoot them down before they reach the tower or the player.
- Multi-Target Radar: Updated the
ZombiIAscript to detect three priorities: Tower, Samurai, and Allies. - Target Management: Zombies now dynamically switch targets if their current victim dies or escapes.
- Shop Updated: Modified
GeneradorAliadosto include purchasing Archers (Cost: 15 coins).
In this phase, the complete game cycle was finalized, improving the impact sensation (Game Juice), adding a final challenge (Boss), rewriting the wave system, and finishing all user interfaces and scene navigation.
- Blood System: Implemented particles upon taking damage. Now, every hit on an enemy instantiates a visual effect that disappears after a few seconds.
- Giant Variant: Created a new "ZombiBoss" enemy (1.5x Scale).
- Buffed Stats: Adjusted health (x5), high damage, and reduced speed to create a "tank".
- Height Sensor:
VueloFantasmascript using a Raycast to detect the ground. - Dynamic Hovering: Automatic vertical adjustment to climb ramps without standard gravity physics.
- Parallel Spawning: New logic that allows simultaneous spawning of different enemy types.
- Tag Detection: The system now waits for the screen to be cleared by detecting the
EnemigoTag.
- State Management: Victory, Defeat, and Pause screens with time freezing (
Time.timeScale). - Navigation: Configured
Build Settingsto connect the Menu and Game scenes.
The focus of this phase was transforming the project into a final Android product by implementing touch controls, balancing difficulty, and drastically improving aesthetics.
- Virtual Joystick: Implemented the
On-Screen Stickcomponent from the New Input System. - Codeless Integration: Mapped the Joystick to the
Player/Moveaction (Gamepad Left Stick), allowing the Samurai to move on mobile without modifying its original script. - Controller UI: Visual design of the joystick (Knob and Background) on the Canvas.
- Parallax/Static Background: Imported 2D art (Feudal Japan) to replace the gray background.
- Sorting Layers: Created and configured rendering layers (
FondovsDefault) to ensure the environment stays behind the characters. - Invisible Ground: Design technique that hides the physical ground's SpriteRenderer (
Floor), allowing the player to interact with the collider while visually "walking" on the drawn path in the background.
- Difficulty Curve: Adjusted key variables to make the game fun but challenging.
- Boss: Massive health increase and coin reward.
- Ghosts: High speed and damage, but low health ("Kamikaze" style enemies).
- Economy: Adjusted unit costs (cheap Farmer, expensive Archer) and starting coins.
- TextMeshPro Font Assets: Imported and "baked" (SDF) stylized Japanese fonts to improve the visual quality of titles and menus.
The goal of this phase was to elevate visual quality ("Game Juice") and user experience (UX). Cinematic systems, persistent particle effects, and a totally revamped thematic interface were implemented.
- Dynamic Zoom: Implemented automatic camera sequences:
- Intro: Smooth zoom-in on the Samurai when starting the match.
- Outro: Panoramic zoom-out upon winning or losing to show the final state of the battlefield.
- Real-Time Management: Used
Time.unscaledDeltaTimein camera scripts to allow fluid animations even when the game is technically paused (TimeScale = 0).
- Fireworks System: Created the
LanzadorFestivoandProyectilFestivologic.- Custom Physics: Rockets with straight trajectories and dynamic rotation so the tip always faces its flight direction.
- Ignore Pause: Configured
Particle SystemstoUnscaled Timemode so explosions continue animating behind the Victory menu.
- UI Animations: Entry effects ("Pop-up" with bounce) for Victory and Defeat banners.
- Thematic Aesthetics: Replaced placeholder buttons with "Samurai" style assets (wood, scrolls, golden frames).
- Iconography: Integrated coin icons into unit costs and the global counter to unify the visual language.
- Clean Layout: Reorganized the Canvas, clearly separating the gameplay HUD, Pause Menu, and End Game screens.
- Victory Screen: High-impact design with a thematic logo, particles, and integrated buttons.
- Game Logic: Full implementation of
PausarJuego()andReanudarJuego()managingTime.timeScale. - UI Integration: Functional pause menu with options to resume or return to the main menu.
- Tutorial Manager: Created a manager script that controls game flow through phases (Intro -> Combat -> Buy Farmer -> Horde -> Buy Archer).
- Dialogue System: Implemented an "Ancient Scroll" UI that pauses the game (
Time.timeScale) to give instructions to the player. - Flying Enemies (Ghosts):
VueloFantasmascript using Raycast to hover at a constant height above the terrain's relief. - Archer AI Improvement: Aim correction by calculating angles and gravity-less physics for arrows.
- Save System (
DatosJugador): Static script based onPlayerPrefsto save progress and the new currency: "Upgrade Points" (Tokens). - The Dojo: Permanent upgrade shop with evolving graphics and a "Respec" (Reset) mechanic to recover points.
- Stat Scaling: Allies now read their saved data when starting a match to dynamically modify health, damage, and range.
- First Campaign Level (Level 1): Created the
Nivel_1scene with anti-farming protection for delivering upgrade points upon completion.
In this final major development phase, the game was completed. The exact progression for all 5 levels was designed, advanced troops were integrated, interfaces were revamped, and an epic narrative and playable conclusion was created.
- Global Interface Adjustments: Reviewed, anchored (Anchors), and unified interfaces (health bars, buttons, menus) across all levels to ensure consistency on multiple resolutions.
- Level 2 (The Tank): Introduced the Ronin, a new melee allied unit with massive area damage and a multi-target radar, ideal for stopping large hordes.
- Level 3 (Ranged Threat): Implemented a new background scenario. Introduced Zombie Archers, forcing the player to adapt their defenses.
- Level 4 (Explosions): Unlocked the Ninja, the ultimate allied unit. Throws bombs with Area of Effect damage and features a smart "Anti-Air Filter" (ignores ghosts to clear ground zombies).
- Dynamic Scaling: Enemies increase their stats (health and damage) depending on the level they appear in, using the
EscalarEstadisticas(nivel)function.
- "The Awakening" Mechanic: The Boss enters in a dormant state. He has a timer before advancing, but will "awaken" instantly if an ally enters his detection range.
- Immovable Physics: Used
RigidbodyConstraints2Dto lock the Boss's X-axis while attacking or sleeping, preventing zombie hordes from pushing him. - Simultaneous Hordes: The
GeneradorEnemigoscounts living enemies selectively (ignoring the Boss), allowing waves to keep flowing continuously while the boss is still alive.
- Credits Scene: Created a cinematic slow-motion transition (
Time.timeScale = 0.5f) upon defeating the Ice King. - Farewell Dialogues: The Mentor returns for a few final words of victory using the scroll system (adapted to the New Input System).
- Hard Reset ("New Legend"): Implemented a final button that uses
PlayerPrefs.DeleteAll()and clears the upgrades shop to allow full replayability from scratch.
Even though the base game is fully complete (v1.0), the scalable architecture allows for easy content additions:
- Survival Mode: An infinite level where waves generate procedurally and difficulty scales endlessly.
- New Environments: Different biomes and terrain mechanics (e.g., areas that slow down characters).
- Active Abilities: On-screen buttons allowing the player to manually cast spells (e.g., Arrow Rain) with cooldowns.
- Animation Improvements: Fix minor animation bugs.