简体   繁体   English

通过触摸Unity C#跳转

[英]Jump by touch Unity C#

I writing game on Unity C# 我在Unity C上写游戏#

This is simple runner. 这是简单的跑步者。

I have Platformer2DUserControl Script. 我有Platformer2DUserControl脚本。

Here is it 就这个

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

I try to make that player jumps when i touch screen on my phone. 当我在手机上触摸屏幕时,我尝试让该播放器跳转。

But it don't jump. 但它不跳。

What wrong in my code? 我的代码有什么问题?

Thank's for help. 感谢帮助。

If you just want the the object to jump on touch use 如果你只是想让对象跳上触摸使用

Input.GetButton("Fire1")

It is predefined to left mouse click and also work for single touch input 它是预定义的鼠标左键单击,也适用于单点触摸输入

Input.GetKeyDown(KeyCode.Space)

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

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

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