玩家触摸输入和连续的单向移动组合

时间:2018-06-05 15:04:08

标签: unity3d

我想制作Mmm Finger 2游戏,如玩家动作,这里是游戏视频:Mmm Fingers 2 by Noodlecake Android Gameplay ᴴᴰ

在此播放器中,根据触摸不断向上移动,您可以完全控制玩家的移动。这两件事对我来说都不合适。基于手指的动作也在各个方向都有效,但你仍在不断前进。

我试图用不同的方式编写一些代码,但无法在游戏中创造流畅的体验。

到目前为止我到达了这里:

void Update ()
{

    // checking condition for death
    if (!isAlive)
        return;

    #if UNITY_EDITOR 
    // executed in Unity editor
    if (Input.GetMouseButtonDown (0)) {

        //Get the mouse position on the screen and send a raycast into the game world from that position.
        Vector2 worldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast (worldPoint, Vector2.zero);

        //If something was hit, the RaycastHit2D.collider will not be null.
        if (hit.collider != null && hit.transform.CompareTag (GameConstants.TAG_HUMAN_PLAYER)) {
            playerFound = true;
            GameManager.Instance.IsGameRunning = true;
            GameHUDController.Instance.HideGameInstruction();
            hidePlayerName();
        }

    } else if (Input.GetMouseButtonUp (0)) {
        playerFound = false;
        StartCoroutine (PerformGameOver ());
    }

    Vector3 nextPosition = transform.position;
    nextPosition.x += (Time.deltaTime * speed * 0.5f);
    transform.position = nextPosition;

    if (playerFound) {
        Vector3 worldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
        //          worldPoint.x += (speed * Time.deltaTime);
        worldPoint.z = 0f;
        transform.position = worldPoint;
        //          transform.position = Vector3.Lerp (transform.position, worldPoint, Time.deltaTime * 10f);

    }
}

请为此提供一些帮助。

0 个答案:

没有答案