Ejemplo n.º 1
0
    public IEnumerator ExitFlow()
    {
        isExiting = true;
        PlayerController.controlsAble = false;
        //Destroy flow parent
        transform.parent = null;
        Destroy(theFlowParent);
        flowMovement = null;
        playerController.anim.SetBool("isSwimming", false);

        //Reset waterControl

        //Init lerp
        GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0);
        Vector3    originPosition = transform.position;
        Quaternion originRotation = transform.rotation;
        Vector3    rayDirection   = detectedExitPoint.GetComponent <ExitPoint> ().GetExitTarget(transform) - transform.position;
        Vector3    targetPosition = new Vector3(0, 0, 0);
        Quaternion targetRotation = new Quaternion(0, 0, 0, 0);

        if (Physics.Raycast(transform.position, rayDirection, out hit, 10f, layer))
        {
            targetPosition = hit.point;
            targetRotation = Quaternion.LookRotation(transform.forward, hit.normal);
        }

        PlayerController.inFlow = false;
        //Lerp & Slerp
        float vol = soundMan.flowSource.volume;

        for (float i = 0; i < 1; i += Time.deltaTime * outSpeed)
        {
            //transform.position = Vector3.Lerp(originPosition, targetPosition, exitCurve.Evaluate(i));
            transform.rotation = Quaternion.Slerp(originRotation, targetRotation, exitCurve.Evaluate(i));

            //Lerp in the flow sound

            soundMan.flowSource.volume = Mathf.Lerp(vol, 0f, i);

            yield return(new WaitForFixedUpdate());
        }

        leftSwimBubbles.Stop();
        rightSwimBubbles.Stop();
        soundMan.flowSource.Stop();
        soundMan.flowSource.volume = vol;
        impactCloud.Play();

        isExiting = false;

        //Switch to not in flow mode
        FlowMode(false);
        PlayerController.controlsAble = true;
        waterControl.ResetFlow();
        currentFlow = null;

        //Reset exit point
        //detectedExitPoint.GetComponent<Renderer>().material.SetFloat("_OutlineSwitch", 0);
        detectedExitPoint = null;
    }