Exemplo n.º 1
0
    /// <summary>
    /// Creates an OverlapSphere at the center of the Instantiated Explosion
    /// </summary>
    public void Explode()
    {
        // Gets all colliders around this GameObject (with a big enough radius)
        Collider[] npcs = Physics.OverlapSphere(transform.position, maxRadius);

        // Iterates through all Colliders found...
        foreach (Collider c in npcs)
        {
            // ...finds the ones with the 'NPC' tag...
            if (c.CompareTag("NPC"))
            {
                // ...fetch its NPC Behaviour script...
                NPCBehaviour npc = c.GetComponent <NPCBehaviour>();

                // ...if the distance is smaller than the kill radius on the moment of the explosion...
                if (Vector3.Distance(transform.position, npc.transform.position) <= killRadius)
                {
                    // ...'kill' the npc...
                    npc.IsDead = true;

                    // ...and update the UI display...
                    explosionManager.UpdateKillCount();

                    // ...and add a big force to it
                    StartCoroutine(NPCAddForce(npc, 500, 100));

                    // ...if the distance is smaller than the stun radius on the moment of the explosion...
                }
                else if (Vector3.Distance(transform.position, npc.transform.position) <= stunRadius)
                {
                    // ...set its stun time...
                    npc.StunTime = explosionManager.StunTime;

                    // ...set the npc as Stunned...
                    npc.IsStunned = true;

                    // ...and also as Panicking (although he won't be able to run)
                    npc.IsPanicking = true;

                    // ...if the distance is smaller than the panic radius on the moment of the explosion...
                }
                else if (Vector3.Distance(transform.position, npc.transform.position) <= panicRadius)
                {
                    // ...set the npc as Panicking (will be able to run)
                    npc.IsPanicking = true;
                }
            }
        }
    }