-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathCharacter.cs
35 lines (31 loc) · 993 Bytes
/
Character.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;
using UnityCheatSheet.Patterns.StrategyPattern.Strategies;
namespace UnityCheatSheet.Patterns.StrategyPattern
{
public class Character : MonoBehaviour
{
private IAttackStrategy attackStrategy;
public Transform target;
private void Start()
{
// Default to melee attack
SetAttackStrategy(new MeleeAttackStrategy());
}
public void SetAttackStrategy(IAttackStrategy strategy)
{
attackStrategy = strategy;
Debug.Log($"Changed to {strategy.GetType().Name} - Range: {strategy.GetRange()}, Damage: {strategy.GetDamage()}");
}
public void PerformAttack()
{
if (attackStrategy != null && target != null)
{
attackStrategy.Attack(transform, target);
}
else
{
Debug.LogWarning("Cannot attack: Missing strategy or target");
}
}
}
}