コード例 #1
0
    //void Awake(){
    //hitboxSpawn = GameObject.Find ("hitboxSpawn").transform;
    //}

    void Update()

    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            AudioSource.PlayClipAtPoint(confirmClip, transform.position);
            GiveControl();
            paused = togglePause();
        }

        float move = Input.GetAxis("Horizontal");

        anim.SetFloat("Speed", move);          //animator speed float
        attack = Input.GetButtonDown("Attack");
        crouch = Input.GetKeyDown(KeyCode.DownArrow);

        /*
         * if(move > 0 && !facingRight)
         *      // ... flip the player.
         *      Flip();
         * // Otherwise if the input is moving the player left and the player is facing right...
         * else if(move < 0 && facingRight)
         *      // ... flip the player.
         *      Flip();
         */
        //here are the actions that are triggered by a press or a release
        if (mPlayer && mHasControl)
        {
            /*if (Input.GetKeyDown (KeyCode.LeftShift))
             *              //{
             *              //AudioSource.PlayClipAtPoint(Footsteps, transform.position);
             *              //}
             *              mPlayer.StartSprint ();
             *
             * if (Input.GetKeyUp (KeyCode.LeftShift))
             *              mPlayer.StopSprint ();
             */
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                //{
                //AudioSource.PlayClipAtPoint(SlideClip, transform.position);
                //}

                mPlayer.Crouch();
            }


            if (Input.GetKeyUp(KeyCode.DownArrow))
            {
                mPlayer.UnCrouch();
            }


            //animator state section

            AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);

            //croucn animation trigger
            if (move == 0 && crouch && stateInfo.nameHash == idleStateHash)
            {
                anim.Play("crouchMei");
                //anim.SetTrigger (crouchHash);
                mPlayer.accelerationWalking = 0;
            }

            //uncrouch animation trigger
            if (Input.GetKeyUp(KeyCode.DownArrow) && stateInfo.nameHash == crouchStateHash)
            {
                anim.SetTrigger(uncrouchHash);
                mPlayer.accelerationWalking = 50;
            }



            //slide animation trigger
            if (move > 0 && crouch && stateInfo.nameHash == runStateHash)
            {
                AudioSource.PlayClipAtPoint(slideClip, transform.position);
                anim.Play("slideMei");
            }
            if (move < 0 && crouch && stateInfo.nameHash == run2StateHash)
            {
                AudioSource.PlayClipAtPoint(slideClip, transform.position);
                anim.Play("slideMei");
            }
            if (move < 0 && crouch && stateInfo.nameHash == runStateHash)
            {
                AudioSource.PlayClipAtPoint(slideClip, transform.position);
                anim.Play("slideMei");
            }
            //slide get up animation trigger
            if (Input.GetKeyUp(KeyCode.DownArrow) && stateInfo.nameHash == slideStateHash)
            {
                anim.SetTrigger(slideupHash);
                AudioSource.PlayClipAtPoint(jumpClip, transform.position);
            }

            //jump animation only while running
            if (Input.GetButton("Jump") && stateInfo.nameHash == runStateHash)
            {
                anim.Play("jumpMei");
            }

            if (Input.GetButton("Jump") && stateInfo.nameHash == run2StateHash)
            {
                anim.Play("jumpMei");
            }

            //neutral jump animation
            if (Input.GetButton("Jump") && stateInfo.nameHash == idleStateHash)
            {
                anim.Play("jumpNeutralMei");
            }
            if (move == 0 && attack && stateInfo.nameHash == crouchStateHash)
            {
                //anim.SetTrigger (sweepHash);
                SweepAttack();
                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
            }
            if (attack && move == 0 && stateInfo.nameHash == idleStateHash)
            {
                //anim.SetTrigger (sweepHash);
                SweepAttack();
                //AudioSource.PlayClipAtPoint(sweepClip, transform.position);
                //anim.Play ("attackSweepMei");
                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
            }


            if (attack && move > 0 && stateInfo.nameHash == runStateHash)
            {
                //anim.SetTrigger (jumpkickHash);
                JumpKick();
                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
                //yield return new WaitForSeconds (animation.clip.length);
                //anim.Play ("idleMei");
            }
            if (attack && move < 0 && stateInfo.nameHash == run2StateHash)
            {
                //anim.SetTrigger (jumpkickHash);
                JumpKick();
                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
            }
            if (attack && move < 0 && stateInfo.nameHash == runStateHash)
            {
                JumpKick();
            }
            if (attack && move < 0 && stateInfo.nameHash == run2StateHash)
            {
                //anim.SetTrigger (jumpkickHash);
                JumpKick();
                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
            }
            if (attack && stateInfo.nameHash == jumpneutralStateHash)
            {
                //anim.SetTrigger (jumpkickHash);
                JumpKick();

                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * -hitboxSpeed);
            }
            if (attack && stateInfo.nameHash == jumpStateHash)
            {
                //anim.SetTrigger (jumpkickHash);
                JumpKick();

                //clone = Instantiate (hitboxPrefab, hitboxSpawn.position, hitboxSpawn.rotation) as Rigidbody;
                //clone.AddForce (hitboxSpawn.transform.right * hitboxSpeed);
            }
        }
    }