• Manual
  • Scripting API
  • Changelog
  • Contact
Search Results for

    Show / Hide Table of Contents
    • Overview
      • Introduction
      • Install Auto-Battle Framework
      • Description of the systems
      • Description of the sample scene
    • Tutorials
      • Getting started
      • Customizing the Battle Grid
      • Create a new Game Character
        • Create a new Trait
      • Create a new Attack Effect
        • Create a new Projectile
        • Create a new Buff Effect
        • Create a new On-Hit Effect
      • Fusion Manager
        • Level Up a Game Character
      • Create a new Game Item
      • Shop Manager
        • Create a new Item List
      • Battle Stage
        • Create a new Preparation State
        • Create a new Fight State
        • Create a new Change Stage State
        • Create a new Battle State
        • Create a new Battle Stage
      • Customize the UI
    • Multiplayer
      • Multiplayer

    Create a new On-Hit Effect

    An On-Hit Effect is an action that occurs when a character hits another character with an attack.

    For example, when a character is hit by another, it can apply extra damage, change its scale, apply a debuff to the enemy (included in the package as ApplyDebuffOnHitEffect) or a buff to itself (included in the package as ApplyBuffOnHitEffect).

    An On-hit Effect can be applied in the following cases:

    • Adding the On-Hit Effect to the On-Hit Effects list in an AttackEffect.
    • Adding the On-Hit Effect to the On-Hit Effects list of Modificator in a Trait.
    • Adding the On-Hit Effect to the On-Hit Effects list of an Item Modificator.

    Let's create an On-Hit Effect that has the effect of draining a fixed amount of energy from the enemy when hitting. We will add it to the Witch's special attack created in Create a new Attack Effect.

    1. Create a new C# script called StealEnergyOnHit. Read the script comments for more information.

    using AutoBattleFramework.BattleBehaviour.GameActors;
    using AutoBattleFramework.Stats;
    using UnityEngine;
    
    namespace AutoBattleFramework.Skills
    {
        /// <summary>
        /// When an attack hits the defender, it removes some energy from it.
        /// </summary>
        [CreateAssetMenu(fileName = "StealEnergyOnHitEffect", menuName = "Auto-Battle Framework/Effects/OnHitEffect/StealEnergyOnHitEffect", order = 1)] //Allows the creation of the Scriptable Object
        public class StealEnergyOnHit : OnHitEffect //Inherits from OnHitEffect
        {
            /// <summary>
            /// Amount of energy to remove on hit.
            /// </summary>
            public int RemoveEnergy = 20;
    
            /// <summary>
            /// When an attack hits the defender, it removes some energy from it.
            /// </summary>
            /// <param name="defender">Defending GameCharacter. In this case it is not necessary.</param>
            /// <param name="attacker">Attacking GameCharacter that will recover life points.</param>
            /// <param name="damage">Damage that has been infringed.</param>
            public override void OnHit(GameCharacter defender, GameCharacter attacker, float damage)
            {
                defender.CurrentStats.AddAmountToStat(CharacterStats.CharacterStat.Energy, -RemoveEnergy);
            }
        }
    }
    

    2. Right click on a project folder, and click on "Create/Auto-Battle Framework/Effects/OnHitEffect/StealEnergyOnHitEffect". This will create a new Scriptable Object of StealEnergyOnHit.

    ![Create the StealEnergyOnHit(~/resources/conhit/1.png) Create the StealEnergyOnHit Scriptable Object.

    3. Select the StealEnergyOnHitEffect and change the value of the amount of energy to be subtracted if desired.

    Set the amount of energy to be subtracted Set the amount of energy to be subtracted.

    4. Select the Witch Special Attack created in Create a new Attack.

    • Edit the Trait description to "Creates an orb that applies 20% of magic damage to the attacker. Bounces indefinitely between enemies. Steal energy on hit.".
    • Add StealEnergyOnHit to the On-Hit Effects list.

    Add StealEnergyOnHit to the On-Hit Effects list of the Witch Special Attack Add StealEnergyOnHit to the On-Hit Effects list of the Witch Special Attack.

    5. Test the game. The Witch should steal mana when the Special Attack projectile hits an enemy.

    Now the witch subtracts energy with her Special Attack. Description has been updated. Now the witch subtracts energy with her Special Attack. Description has been updated.

    • Improve this Doc
    In This Article
    Back to top Auto-Battle Framework documentation