public static ChasingStrategy CreateComponent(GameObject where, float playerDetectionRange = 5f, float acceptableDistanceFromPlayer = 1f, float searchDelay = 1f)
    {
        ChasingStrategy strategy = where.AddComponent <ChasingStrategy>();

        strategy.playerDetectionRange         = playerDetectionRange;
        strategy.acceptableDistanceFromTarget = acceptableDistanceFromPlayer;
        strategy.searchDelay = searchDelay;
        strategy.Start();
        return(strategy);
    }
Example #2
0
    public override void TakeDamage(int damage)
    {
        base.TakeDamage(damage);

        if (health > 0)
        {
            if (!wasHit)
            {
                wasHit = true;
                Destroy(movingStrategy);
                movingStrategy = ChasingStrategy.CreateComponent(gameObject, playerDetectionRange: attackingStrategy.weaponRange + 2f, acceptableDistanceFromPlayer: attackingStrategy.weaponRange - 0.5f, searchDelay: 0.5f);
                movingStrategy.TargetReachedCallback += attackingStrategy.ProcessAttack;
            }

            if (NeedToFlee())
            {
                StartFleeing();
            }
        }
    }
Example #3
0
 // Setting the enemy's strategy.
 public void SetChasingStrategy(ChasingStrategy strategy)
 {
     this.strategy = strategy;
 }