示例#1
0
    // Enable the given emotion, or disable whichever one is being displayed
    public void Emote(bool emoting, EnemyEmotes thisEmote = EnemyEmotes.Confused)
    {
        // If we're going to emote, set the right sprite and cause object to fade in
        if (emoting)
        {
            SpriteRenderer emoteRend;           // Renderer on the emoting object
            Sprite         spriteToDisplay;     // Sprite to display depending on emotion specified

            // Get sprite renderer
            emoteRend = emote.GetComponent <SpriteRenderer> ();

            // Set sprite to display based on emote specified
            if (thisEmote == EnemyEmotes.Confused)
            {
                spriteToDisplay = confusedSprite;
                SoundPlayer.Instance.PlayRandomEffect(distractClips);
            }
            else
            {
                spriteToDisplay = astonishedSprite;
                SoundPlayer.Instance.PlayRandomEffect(catchClips);
            }

            // Display the sprite
            emoteRend.sprite = spriteToDisplay;
            emote.SetBool("Emoting", true);
        }
        // Otherwise, deactivate emoting object
        else
        {
            emote.SetBool("Emoting", false);
            SoundPlayer.Instance.PlayRandomEffect(returnClips);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (health == 0)
        {
            anim.StopPlayback();
            currentEnemyEmotes = EnemyEmotes.NoHealth;
            Destroy(GetComponent <CapsuleCollider>());
            GetComponent <Rigidbody>().useGravity = true;
            deathTimer -= Time.deltaTime;
            if (deathTimer <= 0.0f)
            {
                Destroy(gameObject);
            }
        }
        else
        {
            currentEnemyEmotes = emoteList[health - 1];

            walkCount -= Time.deltaTime;

            if (player.currentEnemy == this)
            {
                attackCount -= Time.deltaTime;
                if (attackCount <= 0.6f)
                {
                    anim.SetTrigger("EnemyAttack");
                }

                if (attackCount <= 0)
                {
                    attackCount = attackReload;
                    Attack();
                }
            }

            if (Vector3.Distance(transform.position, player.transform.position) >= 30.0f)
            {
                Wander();
            }
            else
            {
                Target();
            }


            animCount -= Time.deltaTime;
            if (animCount <= 0)
            {
                animCount = Random.Range(1.0f, animReaload);
                Animate();
            }
        }
    }