-
Notifications
You must be signed in to change notification settings - Fork 0
Gameplay Effects
sajad0131 edited this page Aug 7, 2025
·
1 revision
Gameplay Effects are the primary mechanism for modifying attributes. They can be instant (like taking damage) or have a duration (like a buff or a poison effect).
-
GameplayEffect
: An abstract baseScriptableObject
for all effects. It defines the duration, stacking behavior, and anyGameplayTags
granted to the target. -
InstantModifierEffect
: An effect that applies a one-time modification to an attribute. -
DurationModifierEffect
: An effect that applies a modification for a specific duration. -
GameplayEffectRunner
: AMonoBehaviour
that manages the application and removal of active effects on a character.
- Right-click in the Project window and go to
Create > GAS > Effects
. - Choose either
Instant Modifier
orDuration Modifier
. - Configure the effect's properties in the Inspector.
// In InstantModifierEffect.cs
[CreateAssetMenu(fileName = "NewInstantModifierEffect", menuName = "GAS/Effects/Instant Modifier")]
public class InstantModifierEffect : GameplayEffect
{
[Header("Modifier")]
public AttributeDefinition attribute;
public ModifierType type;
public float value;
public override void Apply(GameObject target, GameObject instigator, int stackCount = 1)
{
var attributeSet = target.GetComponent<AttributeSet>();
if (attributeSet == null || attribute == null) return;
var attrValue = attributeSet.GetAttribute(attribute);
if (attrValue == null) return;
float modValue = value * stackCount;
if (type == ModifierType.Flat)
{
attrValue.BaseValue += modValue;
}
else if (type == ModifierType.Percent)
{
attrValue.BaseValue *= (1 + modValue);
}
}
}