【问题标题】:How can I do the swipe?我该如何刷卡?
【发布时间】:2020-03-20 21:10:48
【问题描述】:

我有一个统一制作的游戏,地铁冲浪者喜欢,一切都完成了,但是: 在笔记本电脑上,我可以使用左右箭头键来移动播放器,但在手机上我不能,没有按钮,没有倾斜,没有滑动,什么都没有。 我在这里附上了我的脚本,请帮助我进行一些控件,但要与左右相同。 谢谢!

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】:

我会说您需要在开始时使用 touch.position 找到手指的位置。确保触摸是触摸。然后继续寻找触摸的位置,直到它移动到你想要的距离为止。然后,调用移动角色的函数。这个统一文档也可以帮助您进行触摸输入。 https://docs.unity3d.com/ScriptReference/Touch.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多