/*
     * void OnAnimatorIK (int layerIndex)
     * {
     *      // Cache the current value of the AimWeight curve.
     *      float aimWeight = anim.GetFloat(hash.aimWeightFloat);
     *
     *      // Set the IK position of the right hand to the player's centre.
     *      anim.SetIKPosition(AvatarIKGoal.RightHand, player.position + Vector3.up * 1.5f);
     *
     *      // Set the weight of the IK compared to animation to that of the curve.
     *      anim.SetIKPositionWeight(AvatarIKGoal.RightHand, aimWeight);
     * }
     */

    void Shoot()
    {
        // The enemy is shooting.
        shooting = true;

        // The fractional distance from the player, 1 is next to the player, 0 is the player is at the extent of the sphere collider.
        float fractionalDistance = (col.radius - Vector3.Distance(transform.position, player.position)) / col.radius;

        // The damage is the scaled damage, scaled by the fractional distance, plus the minimum damage.
        float damage = scaledDamage * fractionalDistance + minimumDamage;

        // The player takes damage.
        playerHealth.TakeDamage(damage);

        // Display the shot effects.
        ShotEffects();
    }
    void OnTriggerStay(Collider other)
    {
        // Debug.Log("EnemyZombieAttack() Stay Trigger Collider");
        // If the player has entered the trigger sphere...
        if (other.gameObject == player)
        {
            // Debug.Log("Player is in Trigger Collider");

            timerToNextBite += Time.deltaTime;

            // Play zombie scream audio.
            AudioSource.PlayClipAtPoint(zScreamClip, transform.position);
            // audioSource.Stop();		// Stop current audio (zombie mosning)

            // canBite = true;
            //
            if (timerToNextBite >= 1 && canBite && timesBit < 1)
            // if(canBite)
            {
                Debug.Log("EnemyZombieAttack() BitePpayer now");

                isBiting        = true;
                canBite         = false;
                timerToNextBite = 0;
                timesBit       += 1;

                // TEST REMOVE UNLESS CONFIRMED.
                // eatPlayer = true;
                // m_Collider.enabled = false; // !m_Collider.enabled



                // Parent enemy zombie to player.
                zombieMain.transform.parent = player.transform;


                // The player takes damage.
                float damage = 100f;                 // later multiply by scale of time, when adding break free mecahnic”
                playerHealth.TakeDamage(damage);
                // Set zombie bite bool in player script to activate zombie bite death process.
                playerHealth.playerDeadBit = true;

                // Get direction to playerZ (fof rotation).
                Vector3 pos = (player.transform.position - zombieMain.transform.position).normalized;

                //create the rotation we need to be in to look at the target
                var _lookRotation = Quaternion.LookRotation(pos);

                //rotate us over time according to speed until we are in the required rotation
                zombieMain.transform.rotation = Quaternion.Slerp(zombieMain.transform.rotation, _lookRotation, Time.deltaTime * 5f);
                // zombieMain.transform.rotation = Quaternion.LookRotation(pos, Vector3.up);

                // Move right behind player (with offset)
                Vector3 desiredPos = new Vector3(player.transform.localPosition.x + 0.5f, player.transform.localPosition.y, player.transform.localPosition.z + 0.1f);
                zombieMain.transform.position = desiredPos;

                // Set world position to keep postion once for unparent.
                Vector3 wPos = transform.TransformPoint(desiredPos);
                // Unparent enemy zombie from player.
                zombieMain.transform.parent = null;


                // anim.SetBool(hash.neckBite, true);
                anim.SetTrigger("Tneckbite");

                var randomNum = Random.Range(0, 4);
                Debug.Log(randomNum);
                // RANDOM START EATING 66%, OR DRAG PLAYER 33% (INTO DARKNESS?)
                if (randomNum >= 3)
                {
                    StartCoroutine("DragPlayer");
                }
                else                // if (randomNumHalf == 2)
                {
                    StartCoroutine("EatPlayer");
                }
            }
        }
    }