How to make this script faster?

How to make this enemy script faster? Any ideas?
Thank you in advice

   void Update()
    {
        if (!animZ.GetCurrentAnimatorStateInfo(0).IsName("TZ_emerge") || isDead)
        {
            if (nav.isStopped == true)
                nav.isStopped = false;    
        }

        if (inRange && !animZ.GetCurrentAnimatorStateInfo(0).IsName("TZ_emerge"))
        {            
            if (!playerStats.playerDead && !isDead)
            {
                if (Vector3.Distance(transform.position, player.position) <= aggroRange)
                {
                    if (isSleeping)
                    {
                        animZ.SetBool("isSleeping", false);
                        aggroRange = aggroTemp;
                        isSleeping = false;
                    }

                    if (animZ.GetCurrentAnimatorStateInfo(0).IsName("RaiseFromDead") && animZ.GetCurrentAnimatorStateInfo(0).normalizedTime <= 0.1f)
                    {
                        audioSource.PlayOneShot(zomb_wakeup);
                    }
                                        
                    if (animZ.GetCurrentAnimatorStateInfo(0).IsName("RaiseFromDead") && animZ.GetCurrentAnimatorStateInfo(0).normalizedTime <= 2f)
                    {
                        nav.isStopped = true;                     
                    }
                    else if (!animZ.GetCurrentAnimatorStateInfo(0).IsName("SleepingZombie") || isDead)
                    {
                        if (nav.isStopped == true)
                            nav.isStopped = false;            
                    }

                    animZ.SetBool("isAggro", true);

                    if (Vector3.Distance(transform.position, player.position) <= chaseRange)
                    {
                        animZ.SetBool("chasePlayer", true);  
                        nav.speed = .37f;   
                    }
                    else
                    {
                        animZ.SetBool("chasePlayer", false);   
                        nav.speed = .24f;     
                    }
                }
                else
                {
                    animZ.SetBool("isAggro", false);   
                    nav.isStopped = true;      
                    Debug.Log("Navmesh Stopped for other reason == TRUE");
                }
            }

            if (!isDead)
            {
                if (!playerStats.playerDead && !animZ.GetCurrentAnimatorStateInfo(0).IsName("TZ_emerge"))
                {
                    nav.SetDestination(player.position);
                }
                animZ.SetFloat("Speed", Mathf.Abs(nav.velocity.x) + Mathf.Abs(nav.velocity.z));
                float distance = Vector3.Distance(transform.position, player.position);


                Vector3 direction = (player.position - transform.position).normalized;
                Quaternion lookRotation = Quaternion.LookRotation(direction);

                // Combat range rotation 
                if (distance <= 1 && !isDead)
                {

                    if (!playerStats.playerDead)
                    {

                        animZ.SetBool("Attack", true);
                        nav.isStopped = true;

                        if (animZ.GetCurrentAnimatorStateInfo(0).IsName("ArmAttacks"))
                            transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 0f);
                        else
                            transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 10f);
                    }
                }
                else if (distance > 1)
                {
                    animZ.SetBool("Attack", false);
                }
                else if (distance > 1 && Vector3.Distance(transform.position, player.position) <= aggroRange)
                {
                    nav.isStopped = false;
                }

                if (canPoise && distance < poisonDistance)
                {
                    poisonAttackTimer += Time.deltaTime;

                    if (poisonAttackTimer > poisonAttackInterval)
                    {
                        int tryToPoise = Random.Range(0, 100);
                        if (tryToPoise <= poisonChance)
                        {
                            player.SendMessageUpwards("PlayerPoisoned", poisonDamage, SendMessageOptions.RequireReceiver);
                            player.SendMessageUpwards("PoiseDuration", poisonDuration, SendMessageOptions.RequireReceiver);
                        }
                        poisonAttackTimer = 0;
                    }
                }


                if (playerStats.playerDead)
                {
                    readyToFeast = true;

                    animZ.SetBool("killedPlayer", true);
                    Vector3 directionDead = (playerRoot.position - transform.position).normalized;
                    Quaternion lookDeadRotation = Quaternion.LookRotation(directionDead);
                    transform.rotation = Quaternion.Slerp(transform.rotation, lookDeadRotation, Time.deltaTime * 10f);
                    transform.rotation = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f));

                    if (Vector3.Distance(transform.position, playerRoot.position) >= 1.2f && (Vector3.Distance(transform.position, playerRoot.position) <= 3f))
                    {
                        transform.position = Vector3.MoveTowards(transform.position, playerRoot.position, Time.deltaTime / 20);
                        Debug.Log("Player Distance = " + Vector3.Distance(transform.position, playerRoot.position));
                        animZ.SetBool("moveToCorpse", true);
                        nav.isStopped = false;
                        nav.speed = .37f;
                    }
                    else
                    {
                        animZ.SetBool("moveToCorpse", false);
                        nav.isStopped = true;
                    }

                    if (readyToFeast)
                    {
                        feastStartTimer += Time.deltaTime;
                    }

                    if (feastStartTimer > 4)
                    {
                        nav.SetDestination(playerRoot.position);
                        transform.position = Vector3.MoveTowards(transform.position, playerRoot.position, Time.deltaTime / 10f);
                        feastStartTimer = 0;
                        readyToFeast = false;
                    }
                }

                if (canPoise)
                {
                    if (distance < poisonDistance)
                    {
                        attackTimer += Time.deltaTime; 
                    }
                    else if (attackTimer > 0)
                    {
                        attackTimer -= Time.deltaTime * 2;    
                        animZ.SetBool("Attack", false);    
                    }
                    else
                    {
                        attackTimer = 0;         
                        animZ.SetBool("Attack", false);    
                    }
                }

            }

            if (!isSleeping && !IdleAudio.isPlaying && health > 0)
            {
                IdleAudio.Play();
            }

            if (hit && !isSleeping)
            {
                animZ.Play("ZTakeDamage");
                hit = false;
            }

            if (health <= 0)
            {
                nav.isStopped = true;
                if (!isDead)
                {
                    audioSource.PlayOneShot(zomb_deathScream);
                    audioSource.PlayOneShot(zomb_deathCracks);
                    IdleAudio.Stop();
                    Death();
                }
            }

            if (isDead && !canBeLooted)
            {
                lootTime();
               //lootCollider.gameObject.layer = 26;
            }


            if (startSpellTimer)
            {
                timedArrackTimer += Time.deltaTime;
            }

            if (timedArrackTimer > 1f)
            {
                float damageN = playerStats.playerMagicDamage / 20;
                ApplyDamage(damageN);
                Debug.Log("HIT ENEMY ZOMBIE with timed Magic " + damageN);
                timedArrackTimer = 0;
            }

            if (inScene && addOnlyOnce)
            {
                addOnlyOnce = false;
                EnemySpawner.enemyCount.Add(this);
            }
        }
    }

Honestly, this is not answerable.

Why?

Because you posted 220 lines of code that you want to be “improved” but we don’t and cannot know what is using up the performance. Yes there are some common things in there which are more expensive then others but as soon as there is any function being used for which the code is not shared then we cannot know what you do in there so we cannot really tell if that needs to be improved or not.

In general when doing optimization follow these simple rules:

1: Use the profiler - it will tell you what the big performance-culprits are. This will give you a point where you can start optimization.
2: Don’t loose yourself in microoptimizations - Is this script actually the one that needs improvement? Will the improvement be noticable or is it 10 hours of rewriting for 0.01ms/frame?

When you can answer the question what in there is using up all the performance then you should repost your question with a more detailed post.

General advice for your script: If your Update is longer than 50 lines - add functions to structure your code. This also will make profiling more intuitive as it will tell you what needs how long by function.

Thank you for the reply and the tips.
I’ve tried to get some idea out of the profiler. However I can’t find it. But when the enemies are not enables it runs so much faster. Quite in fact enemies are a bottle neck and I have them optimized to only be enabled when the player is 60 meter or closer. Also there is not much more other than the script to the enemie. It has an agro range, a chase range and an attack range. All handled in update function above. I thought there might is something wrong with lines like:

if (Vector3.Distance(transform.position, playerRoot.position) >= 1.2f && (Vector3.Distance(transform.position, playerRoot.position) <= 3f))

in general. But I will see to structure the code with more functions and hopefully can get something more out of the debugger.