예제 #1
0
    // OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}



    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        actor = GameObject.FindGameObjectsWithTag("Player")[0].GetComponent <character>();

        if (stateInfo.IsName("pulldown"))
        {
            actor.isHolding             = false;
            actor.rigidbody.isKinematic = false;
            actor.animator.SetBool("pulldown", false);
        }
        else if (stateInfo.IsName("pullup"))
        {
            actor.isHolding             = false;
            actor.rigidbody.isKinematic = false;
            vaultObject aVault = actor.aVaultObject;
            if (aVault)
            {
                actor.rigidbody.MovePosition(aVault.transform.TransformPoint(aVault.curve[1]));
            }
            actor.animator.SetBool("pullup", false);
        }
        else if (stateInfo.IsName("pullup_stair"))
        {
            animator.SetTrigger("climb_end");
            animator.SetBool("pullup", false);
            actor.isClimbing            = false;
            actor.rigidbody.isKinematic = false;
        }
        else if (stateInfo.IsName("idle_vault") || stateInfo.IsName("walk_vault") || stateInfo.IsName("run_vault"))
        {
            animator.ResetTrigger("goslide");
        }
    }
예제 #2
0
    private void LateUpdate()
    {
        if (!isGameDone)
        {
            if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("idle"))
            {
                GetComponent <AudioSource>().pitch = 0.8f;
            }
            else if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("walk"))
            {
                GetComponent <AudioSource>().pitch = 0.9f;
            }
            else if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("run"))
            {
                GetComponent <AudioSource>().pitch = 1f;
            }

            if (aLadder && isClimbing)
            {
                foreach (var clipinfo in animator.GetCurrentAnimatorClipInfo(0))
                {
                    if (clipinfo.clip.name.Equals("climb_slide"))
                    {
                        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1.0f)
                        {
                            if (aLadder.MoveDown())
                            {
                                animator.SetTrigger("climb_end");
                                animator.SetBool("climb_slide", false);
                                isClimbing            = false;
                                rigidbody.isKinematic = false;
                            }
                        }

                        int index = aLadder.currentStep;

                        if (index > 0)
                        {
                            Vector3 lerped = Vector3.Lerp(aLadder.transform.TransformPoint(aLadder.steps[index]), aLadder.transform.TransformPoint(aLadder.steps[index - 1]), animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                            rigidbody.MovePosition(lerped);
                        }
                    }
                    else if (clipinfo.clip.name.Contains("climb"))
                    {
                        float len = clipinfo.clip.length;
                        float cur = len * Mathf.Min(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.999f);

                        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.95f)
                        {
                            Vector3 lerped;
                            if (aLadder.dir)
                            {
                                lerped = Vector3.Lerp(aLadder.transform.TransformPoint(aLadder.steps[aLadder.currentStep - 1]), aLadder.transform.TransformPoint(aLadder.steps[aLadder.currentStep]), cur / len);
                            }
                            else
                            {
                                lerped = Vector3.Lerp(aLadder.transform.TransformPoint(aLadder.steps[aLadder.currentStep + 1]), aLadder.transform.TransformPoint(aLadder.steps[aLadder.currentStep]), cur / len);
                            }
                            rigidbody.MovePosition(lerped);
                        }
                    }
                }
            }
            if (aVaultObject)
            {
                foreach (var clipinfo in animator.GetCurrentAnimatorClipInfo(0))
                {
                    if (clipinfo.clip.name.Contains("_vault"))
                    {
                        rigidbody.isKinematic = true;
                        canVault = false;

                        float len = clipinfo.clip.length;
                        float cur = len * Mathf.Min(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.999f);

                        float gap   = clipinfo.clip.length / (float)(aVaultObject.curve.Length - 1);
                        int   index = (int)(cur / gap);

                        Vector3 lerped;
                        if (animPosition)
                        {
                            lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[aVaultObject.curve.Length - 1 - index]), aVaultObject.transform.TransformPoint(aVaultObject.curve[(aVaultObject.curve.Length - 1) - index - 1]), (cur % gap) / gap);
                        }
                        else
                        {
                            lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[index]), aVaultObject.transform.TransformPoint(aVaultObject.curve[index + 1]), (cur % gap) / gap);
                        }
                        rigidbody.MovePosition(lerped);

                        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.05f)
                        {
                            animator.SetTrigger("goslide");
                            rigidbody.isKinematic = false;
                            animPosition          = !animPosition;
                        }
                    }
                }

                {
                    if (animator.GetCurrentAnimatorStateInfo(0).IsName("pullup") && aLadder)
                    {
                        float len = animator.GetCurrentAnimatorStateInfo(0).length;
                        float cur = len * Mathf.Min(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.999f);

                        Vector3 lerped = Vector3.Lerp(aLadder.transform.TransformPoint(aLadder.steps[aLadder.stepCount - 1]), aVaultObject.transform.TransformPoint(aLadder.steps[aLadder.stepCount - 2]), cur / len);
                        rigidbody.MovePosition(lerped);
                    }
                    if (animator.GetCurrentAnimatorStateInfo(0).IsName("pullup") && aVaultObject)
                    {
                        float len = animator.GetCurrentAnimatorStateInfo(0).length;
                        float cur = len * Mathf.Min(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.999f);

                        Vector3 lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), aVaultObject.transform.TransformPoint(aVaultObject.curve[1]), cur / len);
                        rigidbody.MovePosition(lerped);
                    }
                    if (animator.GetCurrentAnimatorStateInfo(0).IsName("ski"))
                    {
                        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1)
                        {
                            float dist = Vector3.Distance(aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), aVaultObject.transform.TransformPoint(aVaultObject.curve[1]));

                            Vector3 lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[1]), aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), animator.GetCurrentAnimatorStateInfo(0).normalizedTime / dist);
                            rigidbody.MovePosition(lerped);
                            if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime / dist >= 1)
                            {
                                animator.SetTrigger("goslide");
                                animator.SetBool("ski", false);
                                aVaultObject          = null;
                                rigidbody.isKinematic = false;
                                Vector3 r = transform.rotation.eulerAngles;
                                r.x = 0;
                                rigidbody.MoveRotation(Quaternion.Euler(r));
                            }
                        }
                    }
                    if (animator.GetCurrentAnimatorStateInfo(0).IsName("slide_1"))
                    {
                        rigidbody.isKinematic = true;
                        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1)
                        {
                            float dist = Vector3.Distance(aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), aVaultObject.transform.TransformPoint(aVaultObject.curve[1]));

                            Vector3 lerped;
                            if (animPosition)
                            {
                                lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[1]), aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), animator.GetCurrentAnimatorStateInfo(0).normalizedTime / dist);
                            }
                            else
                            {
                                lerped = Vector3.Lerp(aVaultObject.transform.TransformPoint(aVaultObject.curve[0]), aVaultObject.transform.TransformPoint(aVaultObject.curve[1]), animator.GetCurrentAnimatorStateInfo(0).normalizedTime / dist);
                            }
                            lerped.y = transform.position.y;
                            rigidbody.MovePosition(lerped);
                            if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime / dist >= 1)
                            {
                                animator.SetTrigger("goslide");
                                rigidbody.isKinematic = false;
                                animPosition          = !animPosition;
                            }
                        }
                        else
                        {
                            Vector3 pos;
                            if (animPosition)
                            {
                                pos = aVaultObject.transform.TransformPoint(aVaultObject.curve[1]);
                            }
                            else
                            {
                                pos = aVaultObject.transform.TransformPoint(aVaultObject.curve[0]);
                            }
                            pos.y = transform.position.y;
                            rigidbody.MovePosition(pos);
                        }
                    }
                }
            }
        }
    }
예제 #3
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "VaultObject" && !animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("vault"))
        {
            hudscript.setAction(ActionTypes.Vault);
            aVaultObject = other.GetComponent <vaultObject>();
            canVault     = true;
            animPosition = (Vector3.Distance(transform.position, aVaultObject.transform.TransformPoint(aVaultObject.curve[0])) > Vector3.Distance(transform.position, aVaultObject.transform.TransformPoint(aVaultObject.curve[aVaultObject.curve.Length - 1])));
        }
        if (other.tag == "slideObject")
        {
            hudscript.setAction(ActionTypes.Slide);
            aVaultObject = other.GetComponent <vaultObject>();
            canSlide     = true;
            animPosition = (Vector3.Distance(transform.position, aVaultObject.transform.TransformPoint(aVaultObject.curve[0])) > Vector3.Distance(transform.position, aVaultObject.transform.TransformPoint(aVaultObject.curve[aVaultObject.curve.Length - 1])));
        }
        if (other.tag == "ladder")
        {
            hudscript.setAction(ActionTypes.HoldLadder);
            aLadder  = other.GetComponent <ladder>();
            canClimb = true;
        }
        if (other.tag == "ground")
        {
            isGrounded = true;
            if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("_jump") || animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("falling") || animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("pullup"))
            {
                animator.SetTrigger("landing");
            }
        }
        if (other.tag == "slopeGround")
        {
            isGrounded = true;
            if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("_jump") || animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("falling"))
            {
                animator.SetTrigger("landing");
            }

            if (Quaternion.Angle(other.transform.rotation, Quaternion.Euler(0, other.transform.rotation.eulerAngles.y, other.transform.rotation.eulerAngles.z)) > 15.0f)
            {
                aVaultObject = other.GetComponent <vaultObject>();
                if (Vector3.Distance(aVaultObject.transform.TransformPoint(aVaultObject.curve[1]), transform.position) < 5.0f)
                {
                    Vector3 apos = (aVaultObject.transform.position - transform.position), bpos = transform.forward;
                    apos.y = bpos.y = 0;
                    if (Vector3.Angle(apos, bpos) < 30 && Vector3.Angle(apos, bpos) > -30)
                    {
                        animator.SetBool("ski", true);
                        rigidbody.isKinematic = true;
                        Vector3 r = transform.rotation.eulerAngles;
                        r.x = aVaultObject.transform.rotation.eulerAngles.x;
                        rigidbody.MoveRotation(Quaternion.Euler(r));
                    }
                }
            }
        }
        if (other.tag == "holdable")
        {
            canHold      = true;
            aVaultObject = other.GetComponent <vaultObject>();
        }
        if (other.tag == "slip")
        {
            animator.SetTrigger("slip");
        }
        if (other.tag == "coin")
        {
            Destroy(other.gameObject);
            hudscript.setCoinCount(++coin);
        }
        if (other.tag == "Finish")
        {
            finish ff = other.GetComponent <finish>();
            GetComponent <AudioSource>().clip = finishmusic;
            GetComponent <AudioSource>().Play();
            ff.animator.SetTrigger("open");
            isGameDone        = true;
            Screen.lockCursor = false;
            hudscript.GameFinish();
        }
        if (other.tag == "deadzone")
        {
            hudscript.Dead();
            Screen.lockCursor = false;
        }
    }