Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 触摸式跳跃#_C#_Unity3d - Fatal编程技术网

C# 触摸式跳跃#

C# 触摸式跳跃#,c#,unity3d,C#,Unity3d,我在Unity C上写游戏# 这是一个简单的跑步者 我有Platformer2DUserControl脚本 给你 using UnityEngine; using UnitySampleAssets.CrossPlatformInput; namespace UnitySampleAssets._2D { [RequireComponent(typeof (PlatformerCharacter2D))] public class Platformer2DUserControl : Mo

我在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;
    }
}
}
使用UnityEngine;
使用UnitySampleAssets.CrossPlatformInput;
命名空间UnitySampleAssets.\u 2D
{
[需求组件(类型(PlatformerCharacter2D))]
公共类Platformer2DUserControl:monobhavior
{
私有平台字符2D字符;
私人跳远;
私人空间
{
character=GetComponent();
}
私有void更新()
{
如果(Input.touchCount>0)
字符移动(1,错误,跳跃);
如果(!跳转)
//阅读更新中的跳转输入,这样就不会错过按钮按下。
跳转=跨平台输入管理器.GetButtonDown(“跳转”);
}
私有void FixedUpdate()
{
//阅读输入。
bool crouch=Input.GetKey(KeyCode.LeftControl);
//float h=CrossPlatformInputManager.GetAxis(“水平”);
//将所有参数传递给角色控制脚本。
字符移动(1,错误,跳跃);
跳跃=假;
}
}
}
当我在手机上触摸屏幕时,我试图让那个玩家跳起来

但它不会跳

我的代码怎么了


谢谢您的帮助。

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

Input.GetButton("Fire1")
它预定义为鼠标左键单击,也可用于单触输入

Input.GetKeyDown(KeyCode.Space)
据我所知,空间也适用于触摸