繁体   English   中英

通过触摸Unity C#跳转

[英]Jump by touch Unity C#

我在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;
    }
}
}

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

但它不跳。

我的代码有什么问题?

感谢帮助。

如果你只是想让对象跳上触摸使用

Input.GetButton("Fire1")

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

Input.GetKeyDown(KeyCode.Space)

据我所知,SPACE也适用于触控。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM