通过触摸Unity C#跳转

时间:2016-03-03 22:49:48

标签: c# unity3d

我在Unity C#上写游戏

这是一个简单的跑步者。

我有Platformer2DUserControl脚本。

这是

 using UnityEngine;
using UnitySampleAssets.CrossPlatformInput;

namespace UnitySampleAssets._2D

{

[RequireComponent(typeof (PlatformerCharacter2D))]
public class Platformer2DUserControl : MonoBehaviour
{
    private PlatformerCharacter2D character;
    private bool jump ;

    private void Awake()
    {
        character = GetComponent<PlatformerCharacter2D>();
    }

    private void Update()
    {
        if (Input.touchCount > 0)
            character.Move(1, false, jump);

        if (!jump)
        // Read the jump input in Update so button presses aren't missed.
        jump = CrossPlatformInputManager.GetButtonDown("Jump");
    }

    private void FixedUpdate()
    {
        // Read the inputs.
        bool crouch = Input.GetKey(KeyCode.LeftControl);
       // float h = CrossPlatformInputManager.GetAxis("Horizontal");
        // Pass all parameters to the character control script.
        character.Move(1, false, jump);
        jump = false;
    }
}
}

当我在手机上触摸屏幕时,我尝试让该播放器跳转。

但它没有跳跃。

我的代码有什么问题?

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

如果您只想让对象跳转,请使用

Input.GetButton("Fire1")

预定义为鼠标左键单击,也适用于单点触摸输入

答案 1 :(得分:0)

Input.GetKeyDown(KeyCode.Space)

据我了解,SPACE同样适用于触摸。

相关问题