コード例 #1
0
    void Update()
    {
        rbd.AddForce(forwardMovement * Time.deltaTime);

        if (Input.GetMouseButtonDown(0))
        {
            screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
            //  offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, screenPoint.y, screenPoint.z));
        }
        if (Input.GetMouseButton(0) /*&& player.GetComponent<PlayerMovement>().GetIsGrounded*/ && clickOnCharacter && clickClose)
        {
            Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, screenPoint.y, screenPoint.z);

            Vector3 curPosition = cam.ScreenToWorldPoint(curScreenPoint);
            //transform.position = curPosition;
            Vector3 vel = rbd.velocity;
            vel.x = (curPosition.x - player.transform.position.x) * 15;

            if (Mathf.Abs(vel.x) > 50)
            {
                vel.x = (vel.x > 0) ? 50 : -50;
            }
            rbd.velocity = vel;
        }
        else if (Input.GetMouseButton(0) /*&& player.GetComponent<PlayerMovement>().GetIsGrounded*/ && !clickOnCharacter && clickClose)
        {
            Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, screenPoint.y, screenPoint.z);

            Vector3 curPosition = cam.ScreenToWorldPoint(curScreenPoint);
            //transform.position = curPosition;
            Vector3 vel = rbd.velocity;
            vel.x        = (curPosition.x - player.transform.position.x) * 3;
            rbd.velocity = vel;
        }
        else if (!clickOnCharacter || !clickClose)
        {
            Vector3 vel = rbd.velocity;
            vel.x        = 0f;
            rbd.velocity = vel;
        }


        if (Input.GetMouseButtonUp(0))
        {
            Vector3 vel = rbd.velocity;
            vel.x            = 0f;
            rbd.velocity     = vel;
            clickOnCharacter = false;
            clickClose       = false;
            swipeControls.SetClickOnCharacter(false);
        }
        if (swipeControls.GetSwipeUp && player.GetComponent <CollisionManager>().GetIsGrounded)
        {
            player.GetComponent <CollisionManager>().SetIsGrounded(false);
            Vector3 curScreenPoint  = new Vector3(screenPoint.x, screenPoint.y, screenPoint.z);
            Vector3 jumpDestination = new Vector3(player.position.x, player.position.y + 5f, player.position.z);
            Vector3 curPosition     = cam.ScreenToWorldPoint(curScreenPoint);
            Vector3 vel             = rbd.velocity;
            vel   = (jumpDestination - curPosition) * 4.5f;
            vel.x = 0;
            //vel.z = rbd.velocity.z * 0.3f;
            rbd.velocity = vel;
            swipeControls.SetSwipeUp(false);
            animator.SetBool("Not ground", true);
            animator.SetBool("SwipeUp", true);


            //  player.transform.position = Vector3.MoveTowards(player.transform.position, desiredPosition, step);
        }
        if (swipeControls.GetSwipeDown && !player.GetComponent <CollisionManager>().GetIsGrounded)
        {
            rbd.AddForce(-jumpingMovement * Time.deltaTime, ForceMode.Impulse);
            //  animator.SetBool("SwipeDown", true);
        }
        else if (swipeControls.GetSwipeDown && player.GetComponent <CollisionManager>().GetIsGrounded)
        {
            animator.SetTrigger("SwipeDown");
        }

        //    Debug.Log(forwardMovement.z);
    }