Input 统一输入触摸问题

Input 统一输入触摸问题,input,touch,Input,Touch,你能告诉我如何在Unity中使用输入触摸功能,使对象在用户每次点击屏幕时改变其x方向吗。例如,对于2d设置游戏,对象在x位置向前(向右)移动,如果用户点击,则对象将在x位置向后移动(向左)。抱歉,没有生成代码。很简单,您的名字“tony”: 你能做的就是制作一个简单的脚本,将你的对象左右移动。在触摸屏上,您只需-1乘法即可轻松改变其方向 可以附加到对象的简单脚本 using UnityEngine; using System.Collections; public class MoveObje

你能告诉我如何在Unity中使用输入触摸功能,使对象在用户每次点击屏幕时改变其x方向吗。例如,对于2d设置游戏,对象在x位置向前(向右)移动,如果用户点击,则对象将在x位置向后移动(向左)。抱歉,没有生成代码。

很简单,您的名字“tony”:

你能做的就是制作一个简单的脚本,将你的对象左右移动。在触摸屏上,您只需-1乘法即可轻松改变其方向

可以附加到对象的简单脚本

using UnityEngine;
using System.Collections;

public class MoveObject : MonoBehaviour
{
    float _limit = 5;

    // 1 for right and -1 for left.
    float _direction = 1;

    // You can call it as speed
    float _speed = 0.01f;


    void Start ()
    {

    }

    void Update ()
    {
        transform.position = Vector3.MoveTowards (transform.position, new Vector3 (transform.position.x + _direction, transform.position.y, transform.position.z), _speed);

        if (Input.GetMouseButtonDown (0))
            _direction *= -1;
    }
}

希望这有帮助:)

嗨,哈姆扎,哈哈,谢谢你的意见:)。我会尝试一下让你知道。嗨,哈姆扎,它工作得很好,非常感谢你的帮助:)。嗨,托尼,如果它工作得很好,请将它标记为答案,以便其他人可能知道它正在工作