Exemple #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);
    }
Exemple #2
0
    void Start()
    {
        agent = GetComponent <NavMeshAgent>();
        hp    = player.GetComponent <EnemyHPController>();
        agent.updatePosition = true;
        agent.updateRotation = true;

        state = moveAgent.State.PATROL;

        alive = true;

        StartCoroutine("FSM");
        waypointInd = Random.Range(0, waypoints.Length - 1);
        healthInd   = Random.Range(0, healthSpots.Length - 1);
        target      = null;
    }
Exemple #3
0
 void Awake()
 {
     hpController = GetComponent <EnemyHPController>(); //Pobranie kontrolera hp
 }