void LateUpdate()
    {
        frames++;
        if (frames >= interval)
        {
            frames = 0;
            bo = getRect(boatOar);

            rg = getRect(dolphinCollider);
            if ((currentState != dolphinStates.swatted || currentState != dolphinStates.escaping || currentState != dolphinStates.alert || currentState != dolphinStates.swimming) && playerIdle == false)
            {
                if (Intersect(rg, bo))
                {
                    currentState = dolphinStates.swatted;
                }
            }

            if (gameObject.transform.position.x > 20 || gameObject.transform.position.x < -20 || gameObject.transform.position.y < -10)
            {
                transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
                //gameObject.transform.rotation.eulerAngles.y = startRotationY;
                transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                //gameObject.transform.localScale.z = startLocalZ;
                gameObject.SetActive(false);
            }
        }
    }
    public void PreAttack()
    {
        if (animator.GetInteger("dolphin_int") != 1)
        {
            animator.SetInteger("dolphin_int", 1);
            PreAttackCounter = Time.time + PreAttackTimer;

            if (baconSpotScript.hasBacon == false)
            {
                attackBacon = false;
                //transform.Rotate(Vector3.back * 30f);
            }
            else
            {
                attackBacon = true;
            }
            transform.Rotate(Vector3.back * 30f);

        }

        //print("T = " + Time.time + "| ac = " + alertCounter);
        if (Time.time > PreAttackCounter)
        {
            if(attackBacon)
            {
                currentState = dolphinStates.grabbing;
            }
            else
            {
                currentState = dolphinStates.attacking;
            }

        }
    }
    public void Swim()
    {
        if (animator.GetInteger("dolphin_int") != 0)
        {
            animator.SetInteger("dolphin_int", 0);
            SwimCounter = Time.time + SwimTimer;
        }

        if(goRight)
        {
            gameObject.transform.Translate(new Vector3(-1 * 6f * Time.deltaTime, 0f, 0f));
        }
        else
        {
            gameObject.transform.Translate(new Vector3(-1 * 6f * Time.deltaTime, 0f, 0f));
        }

        //the stopping position should be random within a range
        if (Mathf.Abs(transform.position.x) < 7.5f)
        {
            currentState = dolphinStates.preAttack;
        }
    }
    public void Grab()
    {
        if (animator.GetInteger("dolphin_int") != 3)
        {
            animator.SetInteger("dolphin_int", 3);

            //transform.Translate(0f, -0.35f, 0f);
            //transform.Rotate(0f, 0f, 120f);
            transform.Rotate(Vector3.back * -30f);
            GrabCounter = Time.time + GrabTimer;
            getBaconState = 1;
        }
        //hit test
        //Rect rb = getRect(baconSpot);

        string StrBacon = baconSpotScript.gameObject.name;
        //print(StrBacon + "/Bacon");
        //GameObject baconGO = GameObject.Find(StrBacon + "/Bacon");
        //rbs = getRect(baconGO);

        int direction = -1;
        if (!goRight)
        {
            direction = -1;
        }

        switch (getBaconState)
        {
            case 1:
                transform.Translate(new Vector3(direction * 0.18f, 0f, 0f));
                //print("get bacon case 1 movement");
                break;

            case 2:
                transform.Translate(new Vector3(direction * 0.08f, 0f, 0f));
                //print("get bacon case 2 movement");
                break;
            case 3:
                transform.Translate(new Vector3(direction * -0.1f, 0f, 0f));
                //print("get bacon case 3 movement");
                break;

        }

        //b = boatEdge.renderer.bounds;
        if ((Intersect(rb, rg)) && (getBaconState == 1))
        {
            //print ("boat bounds hit");

            transform.Rotate(Vector3.back * 25f);
            getBaconState = 2;

        }

        if ((Intersect(rbs, rg)) && (getBaconState == 2)) //(rbs.Overlaps(rg) && (getBaconState == 2))
        {
            if(!grabBacon)
            {

                grabBaconEvent(baconSpot.name);
                grabBacon = true;
                getBaconState = 3;
            }

        }

        if (Time.time > GrabCounter)
        {
            currentState = dolphinStates.escaping;
        }
    }
    public void GetHit(int clearingEnemy = 0)
    {
        if (hit == false)
        {
            hitTime = Time.time + hitAnimationTime;
            currentState = dolphinStates.swatted;
            hit = true;
            //print("hit recieved");
            animator.SetInteger("dolphin_int", 5);
            Toolbox.Instance.dolphinHitCount++;
            if (clearingEnemy == 0)
            {
                DolphinHitEvent(boatOar.transform.position);
            }
            else
            {
                DolphinHitEvent(gameObject.transform.position);
            }

            DolphinPointsEvent(gameObject.transform.position, 30);

        }

        if (Time.time > hitTime)
        {
            currentState = dolphinStates.escaping;
        }
    }
    public void Fire()
    {
        baconSpotScript = baconSpot.GetComponent<CookingController>();

        if ((transform.position.x) < 0)
        {
            goRight = true;
            //p2dControl.flip = false;
            FlipGameObject(dolphinOrientation.facingRight);
        }
        else
        {
            goRight = false;
            //p2dControl.flip = true;
            FlipGameObject(dolphinOrientation.facingLeft);
        }

        //print("boat edge" + boatEdge);

        startRotationY = transform.rotation.eulerAngles.y;
        startLocalZ = transform.localScale.z;
        //print("starting Y = " + startRotationY);
        currentState = dolphinStates.alert;
    }
    public void Attack()
    {
        if (animator.GetInteger("dolphin_int") != 2)
        {
            animator.SetInteger("dolphin_int", 2);
            transform.Translate(0f, -0.5f, 0f);
            transform.Rotate(0f, 0f, 180f);

            AttackCounter = Time.time + AttackTimer;
            splashEvent(new Vector3(gameObject.transform.position.x,gameObject.transform.position.y + 0.2f, gameObject.transform.position.z));

        }

        transform.Rotate(Vector3.forward * (0.5f));

        dolphin.transform.Rotate(0f, 0f, -300.0f * Time.deltaTime);
        transform.Translate(new Vector3(1 * 11f * Time.deltaTime, 0f, 0f));

        //hit test
        pr = getRect(playerHitArea);
        //rg = getRect(objectMesh);

        if (pr.Overlaps(rg))
        {
            if(!playerAttacked)
            {
                DolphinAttackEvent(12f);
                playerAttacked = true;
            }

        }

        if (Time.time > AttackCounter)
        {
            currentState = dolphinStates.escaping;
        }
    }
    public void Alert()
    {
        if (animator.GetInteger("dolphin_int") != -1)
        {
            animator.SetInteger("dolphin_int", -1);
            AlertCounter = Time.time + AlertTimer;
        }

        if (Time.time > AlertCounter)
        {
            currentState = dolphinStates.swimming;
        }
    }