Наследование: MonoBehaviour
Пример #1
0
    void Update()
    {
        timer += Time.deltaTime;
        // If the enemy can attack, the player is in range and the enemy still has health, execute attack.
        if (timer >= timeBetweenAttacks && playerInRange && GetComponent <EnemyHealth>().currentHealth > 0)
        {
            // If there is a sound associated, play it
            if (attackSound != null)
            {
                SfxScript.playSound(attackSound);
            }

            // If there is an animation associated, play it
            if (anim != null)
            {
                EnemyAnimatorController.ExecuteAnimation(anim, "Attack");
            }
            else
            {
                // Exclusive animation for the spider model
                attackAnimation();
            }
            Attack(player);
        }
    }
Пример #2
0
 // Display the death screen
 void displayDeathScreen()
 {
     popupDisplaying = true;
     Time.timeScale  = 0.0f;
     SfxScript.playSound(loseSound);
     deadScreen.SetActive(popupDisplaying);
     AchievementManager.Instance.OnLevelLoss();
 }
Пример #3
0
 void Awake()
 {
     if (instance == null)
     {
         instance   = this;
         this.sound = GetComponentInChildren <AudioSource>();
     }
     else
     {
         // Self-destruct if another instance exists
         Destroy(this);
         return;
     }
 }
Пример #4
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         this.sound = GetComponentInChildren<AudioSource>();
     }
     else
     {
         // Self-destruct if another instance exists
         Destroy(this);
         return;
     }
 }
Пример #5
0
    // Displays the win screen and updates the score on it
    void displayWinScreen()
    {
        popupDisplaying = true;
        Time.timeScale  = 0.0f;
        int        temp1 = TEMPScoreScript.Instance.GetScore();
        int        temp2 = TEMPScoreScript.Instance.GetEnemies();
        GameObject time  = GameObject.Find("Timer");
        int        temp3 = time.GetComponent <Timer> ().getMinutes();
        int        temp4 = time.GetComponent <Timer> ().getSeconds();

        winScreen.GetComponent <WinUpdate> ().SetFinal(temp1, temp2, temp3, temp4);
        SfxScript.playSound(winSound);
        winScreen.SetActive(popupDisplaying);
        AchievementManager.Instance.OnLevelEnd();
    }
Пример #6
0
    public void TakeDamage(int amount)
    {
        // Reduce current health by the amount of damage taken.
        currentHealth -= amount;

        // Trigger hurt sound if it exists
        if (hurtSound != null)
        {
            SfxScript.playSound(hurtSound);
        }

        // Trigger hurt animation if it exists
        if (anim != null)
        {
            EnemyAnimatorController.ExecuteAnimation(anim, "Hit");
        }

        // Trigger flash if it exists
        EnemyFlash flash = this.gameObject.GetComponent <EnemyFlash>();

        if (flash != null)
        {
            StartCoroutine(flash.Flash());
        }

        // If the current health is less than or equal to zero
        if (currentHealth <= 0)
        {
            if (isDead == false)
            {
                isDead = true;
                Debug.Log("Enemy Destroyed!");
                if (this.tag == "Enemy" || this.tag == "Boss")
                {
                    // Increment score when destroyed.
                    Debug.Log("INCREMEMNTING!");

                    // Increment the score
                    TEMPScoreScript.Instance.IncrementScore(scoreAwarded);
                }

                // Play death sound if it exists
                if (deathSound != null)
                {
                    SfxScript.playSound(deathSound);
                }

                // Play death animation if it exists
                if (anim != null)
                {
                    EnemyAnimatorController.ExecuteAnimation(anim, "Die");
                }

                // Play spider aninimation exclusively
                SpiderAnimation temp = GetComponent <SpiderAnimation>();
                if (temp != null)
                {
                    Debug.Log("THIS IS A SPIDER!");
                    temp.spiderKilled();
                }
                else
                {
                    Destroy(gameObject, 1f);
                }
            }
        }
    }