예제 #1
0
    public void Damage(int damage)
    {
        if (gameObject.tag == "Player")
        {
            GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
            Invoke("DisableVibrate", 0.3f);
        }
        if (!isInvincible)
        {
            currentHealth -= damage;
            if (canRespawn)
            {
                Camera.main.GetComponent <CameraShake>().Activate(0.05f, .1f);
                //if (audioSource != null)
                //{
                audioSource.clip = hitClip;
                audioSource.Play();
                //}

                GameManager.health -= damage;
                GameManager.ui.UpdateViews();

                isInvincible = true;

                overlay.FlashOverlay();
            }
            else if (gameObject.GetComponent <AICharacterControl>() != null)
            {
                particle = Instantiate(particleR,
                                       new Vector3(transform.position.x, transform.position.y + 1, transform.position.z),
                                       Quaternion.identity);
                gameObject.GetComponent <AICharacterControl>().SetIsFollowing(true);
                StartCoroutine(gameObject.GetComponent <EnemyFlicker>().Flicker());
            }

            if (currentHealth <= 0)
            {
                if (canRespawn)
                {
                    //if (audioSource != null)
                    //{
                    audioSource.clip = faintClip;
                    audioSource.Play();
                    //}


                    respawn.Activate();
                    currentHealth      = totalHealth;
                    GameManager.health = totalHealth;
                    GameManager.score -= 50;
                    GameManager.ui.UpdateViews();
                }
                else if (gameObject.GetComponent <AICharacterControl>() != null)
                {
                    gameObject.GetComponent <AICharacterControl>().Die();
                }
                else if (gameObject.GetComponent <BossBattle>() != null)
                {
                    gameObject.GetComponent <BossBattle>().Die();
                }
                else
                {
                    Destroy(gameObject);
                }
            }
        }
    }