Beispiel #1
0
    /// <summary>
    /// Dispose of unnecessary components
    /// </summary>
    private void CleanAfterDeath()
    {
        //Play enemy death animation
        Animator animator = gameObject.GetComponentInParent <Animator>();

        if (animator != null)
        {
            animator.SetBool("isDead", true);
        }

        //Set new size of BoxCollider2D (obstacle)
        BoxCollider2D bc = GetComponent <BoxCollider2D>();

        if (bc != null)
        {
            bc.size   = new Vector2(bc.size.x, 0.3f);
            bc.offset = new Vector2(bc.offset.x, -0.5f);
        }
        //Dispose of parent's BoxCollider2d (trigger)
        BoxCollider2D parentBC = transform.parent.gameObject.GetComponent <BoxCollider2D>();

        if (parentBC != null)
        {
            Destroy(parentBC);
        }

        //Dispose of parent's EnemyActivation script
        EnemyActivation ea = transform.parent.gameObject.GetComponent <EnemyActivation>();

        if (ea != null)
        {
            Destroy(ea);
        }

        //Dispose of DamageDealer sibling object
        GameObject damageDealer = transform.parent.gameObject.transform.GetChild(0).gameObject;

        if (damageDealer != null)
        {
            Destroy(damageDealer);
        }

        //Dispose of EnemyHPController script component
        EnemyHPController hpController = gameObject.GetComponent <EnemyHPController>();

        if (hpController != null)
        {
            Destroy(hpController);
        }

        //Dispose of EnemyDamageReceiver script component
        Destroy(this);
    }
Beispiel #2
0
    IEnumerator Start()
    {
        activations.Sort((a, b) =>
        {
            if (a.activateAfterTime < b.activateAfterTime)
            {
                return(-1);
            }
            if (a.activateAfterTime > b.activateAfterTime)
            {
                return(1);
            }
            return(0);
        });

        float time = 0f;

        for (int i = 0; i < activations.Count; ++i)
        {
            int             index      = i;
            EnemyActivation activation = activations[index];

            float waitTime = activation.activateAfterTime - time;
            if (waitTime > 0)
            {
                yield return(new WaitForSeconds(waitTime));
            }

            activation.enemy.SetActive(true);
            activation.enemy.GetComponent <Health>().OnDeath += () =>
            {
                RecordEnemyDead(index);
            };
            time = activation.activateAfterTime;
        }
    }
Beispiel #3
0
 private void CacheComponents()
 {
     stickmanEvents  = GetComponent <StickmanEvents>();
     follower        = GetComponent <SplineFollower>();
     enemyActivation = GetComponent <EnemyActivation>();
 }