Example #1
0
    public void ApplyDamage(float points)
    {
        agent.destination       = playerTransform.position;
        npcHP                  -= points;
        enemyAnim.currentTarget = playerTransform.position;

        if (npcHP <= 0)
        {
            audioSource.clip = enemyDeathSounds[Random.Range(0, enemyDeathSounds.Length)];
            audioSource.Play();
            //Destroy the NPC
            GameObject npcDead = Instantiate(npcDeadPrefab, transform.position, transform.rotation);
            //Slightly bounce the npc dead prefab up
            //npcDead.GetComponent<Rigidbody>().velocity = (-(playerTransform.position - transform.position).normalized * 8) + new Vector3(0, 5, 0);
            Destroy(npcDead, 10);
            //es.EnemyEliminated(this);
            Destroy(gameObject);
        }

        else
        {
            audioSource.clip = enemyHitSounds[Random.Range(0, enemyHitSounds.Length)];
            audioSource.Play();

            enemyAnim.DamageGiven(npcHP, maxHP);
        }
    }