Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Transform detectedObject = collision.gameObject.transform.parent;
        float     detectedObjectPriority;

        if (detectedObject != null)
        {
            // TO:DO use Troop data to find if the detected object is an enemy
            if (troopData.isEnemy != TargetIsEnemy(detectedObject))
            {
                detectedObjectPriority = GetTargetPriority(detectedObject);

                if (detectedObjectPriority > actualTargetPriority)
                {
                    if (ActualTarget != null)
                    {
                        closeTargets.Add(ActualTarget);
                    }

                    if (attackAction.IsAttacking)
                    {
                        attackAction.StopAttack();
                    }

                    ActualTarget = detectedObject;
                }
                else if (!closeTargets.Contains(detectedObject))
                {
                    closeTargets.Add(detectedObject);
                }
            }
        }
    }
    public override void Die()
    {
        TroopAttackActions attackAction = GetComponent <TroopAttackActions>();

        if (attackAction.IsAttacking)
        {
            attackAction.StopAttack();
        }

        if (deathEffect != null)
        {
            Instantiate(deathEffect, transform.position, transform.rotation);
        }

        Destroy(gameObject);
    }