Exemplo n.º 1
0
    private void Move()
    {
        //moveDirection = new Vector2(pTest.moveDirection, rb.velocity.y / speed);
        moveDirection = new Vector2(pManager.direction.x, rb.velocity.y / speed);
        //入力があるとき
        if (Mathf.Abs(moveDirection.x) >= 0.05f)
        {
            pac.EndSleep();
            flag = false;

            if (sleep && anim.GetCurrentAnimatorStateInfo(0).IsName("待機"))
            {
                sleep = false;
            }
            //rb.AddForce(moveDirection);
            if (!sleep)
            {
                isMove      = true;
                rb.velocity = moveDirection * speed;
                Turn();
                if (Mathf.Abs(moveDirection.x) >= 0.05f)
                {
                    if (!isInWater)
                    {
                        pac.StartWalk();
                    }
                    else
                    {
                        pac.StartSwim();
                    }
                }
            }
        }
        //入力がないとき
        else
        {
            isMove = false;
            //加速度を0にして移動を止める(慣性をなくす)
            pac.EndWalk();
            pac.EndSwim();
            rb.velocity = new Vector3(0.0f, rb.velocity.y, 0.0f);
            if (!flag && pc.penguinCount == 0)
            {
                stoptime = Time.time;
                flag     = true;
            }
            if (Time.time - stoptime > 60.0f && pc.penguinCount == 0)
            {
                sleep = true;
                pac.Sleep();
            }

            if (pc.penguinCount > 0)
            {
                pac.EndSleep();
            }
        }

        if (isInWater)
        {
            rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y * 0.99f, rb.velocity.z);
        }
        if (sEnd.isGameOver)
        {
            rb.velocity = Vector3.zero;
        }
    }