【问题标题】:Jump by touch Unity C#触摸跳转 Unity C#
【发布时间】:2018-08-24 02:26:11
【问题描述】:

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

当我在手机上触摸屏幕时,我试图让那个播放器跳跃。

但它不会跳。

我的代码有什么问题?

感谢您的帮助。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    如果您只想让对象在触摸时跳转,请使用

    Input.GetButton("Fire1")
    

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

    【讨论】:

      【解决方案2】:
      Input.GetKeyDown(KeyCode.Space)
      

      据我了解,SPACE 也适用于触控。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多