我如何刷卡?

问题描述 投票:-1回答:1

我有一个由团结,地铁冲浪者共同完成的游戏,但所做的一切:在笔记本电脑上,我可以使用左右箭头键来移动播放器,但是在手机上,我不能,没有按钮,没有倾斜,没有滑动,什么也没有。我在此处附加了脚本,请为我提供一些控件,但请确保左右的值相同。谢谢!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [Range(-2, 2)] public float value;
    public float Speed;
    Rigidbody rigid;
    private Transform player;
    private Vector3 desiredPosition;
    void Start()
    {
        rigid = GetComponent<Rigidbody>();
    }
    void FixedUpdate()
    {
        transform.position = new Vector3(value, transform.position.y, transform.position.z);
        rigid.velocity = (Vector3.forward * Time.deltaTime * Speed);
    }
    private void LateUpdate()
    {
        if (Input.GetButtonDown("Right"))
        {
            if (value == 2)
                return;
            value += 2;
        }
        if (Input.GetButtonDown("Left"))
        {
            if (value == -2)
                return;
            value -= 2;
        }
    }
}
c# unity3d controls swipe
1个回答
0
投票

我想说的是,您首先需要使用touch.position找到手指的位置。确保触摸是触摸。然后继续找到触摸的位置,直到它移动到所需的距离为止。然后,调用移动字符的函数。这个统一的文档可能对您的触摸输入也有帮助。https://docs.unity3d.com/ScriptReference/Touch.html

© www.soinside.com 2019 - 2024. All rights reserved.