コード例 #1
0
        // Update is called once per frame
        void Update()
        {
            transform.position += movement.Calculate(
                unityService.GetAxis("Horizontal"),
                unityService.GetDeltaTime());

            if (unityService.GetAxis("Horizontal") != 0 &&
                !soundManager.IsPlayingSound(GetComponent <AudioSource>()))
            {
                soundManager.Play(GetComponent <AudioSource>());
            }
        }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(GetPosition().x);
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, layerGround);
        animator.SetBool("Grounded", grounded);
        speed = baseSpeed + speedLevel * speedPerLevel;
        //Debug.Log(currentAnim);

        //checking if the player is in an animation(r.g. attacking)
        inAction = attacking || shooting;

        //Debug.Log(grounded);
        //Debug.Log(XSpeedCheck());
        lookdirection = new Vector2(transform.localScale.x, 0);

        // -- Handle input and movement --

        float inputX = UnityService.GetAxis("Horizontal");

        //float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction

        ChangeLookDirection(inputX);

        if (!staggered)
        {
            Move(inputX);
        }
        //body2d.velocity = new Vector2(inputX * speed * speedMod, body2d.velocity.y);

        if (body2d.velocity.y < 0)
        {
            body2d.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
        }

        //Attack
        if (!inAction)
        {
            //without unityServiceL Input.GetKeyDown(KeyCode.K)

            if (UnityService.GetMouseButtonDown1() || Input.GetKeyDown(KeyCode.K)) //can move to below?tbc
            {
                ShootArrow();
            }
            else if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.J)))
            {
                StartAttack();
            }
            else if (Input.GetKeyDown("q"))
            {
                Punch();
            }
        }


        //Jump
        if (Input.GetKeyDown("space") && grounded)
        {
            Jump();
        }


        //Run
        //tbc



        //state for loop animations.
        else if ((Mathf.Abs(inputX) > Mathf.Epsilon) && grounded)
        {
            animator.SetInteger("AnimState", 1);
            //x = 1;
        }
        //falling
        else if ((body2d.velocity.y <= 0) && !grounded)
        {
            animator.SetInteger("AnimState", 2);
            //x = 2;
        }
        //falling

        //Idle
        else
        {
            animator.SetInteger("AnimState", 0);
            //x = 0;
        }

        //Debug.Log(x);
    }