Example #1
0
    IEnumerator CheckForCrab()
    {
        bool hitCrab = false;

        while (true)
        {
            if (!hitCrab && Util.SquareDistance(transform.position, targetCrabTrans.position) < contactDistance * contactDistance)
            {
                targetCrabScript.GetAttacked(damage);
                hitCrab = true;
                AudioManager.Instance.PlayAudio(transform.position, "Thump");
            }
            yield return(null);
        }
    }
Example #2
0
    IEnumerator Attack()
    {
        //GO IN FOR THE CRAB
        bool  targetHit = false;
        float speed     = farSpeed;

        while (!targetHit)
        {
            transform.LookAt(targetCrabTrans);
            transform.position = Vector3.MoveTowards(transform.position, targetCrabTrans.position, speed * Time.deltaTime) + transform.right * Mathf.Sin(Time.time * 20) * .1f;

            float distanceToCrab = Util.SquareDistance(transform.position, targetCrabTrans.position);
            if (distanceToCrab < closeDistance * closeDistance)
            {
                speed = closeSpeed;
            }
            if (distanceToCrab < contactDistance * contactDistance)
            {
                targetCrabScript.GetAttacked(damage);
                targetHit = true;
                AudioManager.Instance.PlayAudio(transform.position, "Eel Attack", volume: 0.5f);
            }
            else
            {
                speed = farSpeed;
            }
            yield return(null);
        }

        //TARGET HIT, RETREAT
        transform.LookAt(exitPosition);
        while (true)
        {
            transform.position = Vector3.MoveTowards(transform.position, exitPosition, exitSpeed * Time.deltaTime) + transform.right * Mathf.Sin(Time.time * 8) * .1f;
            if (Util.SquareDistance(transform.position, exitPosition) < .5f)
            {
                break;
            }
            yield return(null);
        }

        if (!renderer.isVisible)
        {
            Die();
        }
    }