[英]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.