触摸无法在Android设备上的Unity上使用

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

我正在使用Unity remote 5,并且我试图制作一个简单的图像库,如果您按屏幕右侧的按钮,它将向前移动,如果您按左侧的图像,则移动bakcwards ...

问题在于,即使使用“ Debug.Log(Input.touchCount);”也没有注册任何触摸。没有任何输入,我也不知道出什么问题。

这里是代码:

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


public class Diapositiva{

public string nombre;
public string descripcion;
public Sprite imagen;

public Diapositiva(string _nombre,string _descripcion, string _imagen){

    nombre = _nombre;
    descripcion = _descripcion;
    imagen = Resources.Load<Sprite>(_imagen);

}


}

public class Controlador : MonoBehaviour {

public Text nombre;
public Text descripcion;
public Image dibujo;
public int indice = 0;

public List<Diapositiva> Diapositivas = new List<Diapositiva>();

public void LoadDiapositivas(){
    nombre.text= Diapositivas[indice].nombre;
    descripcion.text= Diapositivas[indice].descripcion;
    dibujo.sprite = Diapositivas[indice].imagen;
}

void Left()
{

    if (indice <= 0) indice = Diapositivas.Count - 1;

    else indice--;
    LoadDiapositivas();

}

void Right()
{

    if (indice >= Diapositivas.Count - 1) indice = 0;

    else indice++;
    LoadDiapositivas();

}

// Use this for initialization
void Start () {

    Diapositivas.Add(new Diapositiva("Darinka", "Mi amorcito", "Sprites/Darinka"));
    Diapositivas.Add(new Diapositiva("Hitler", "Heroe de Alemania", "Sprites/Hitler"));
    Diapositivas.Add(new Diapositiva("Nikola Tesla", "Científico mas inteligente del mundo", "Sprites/Tesla"));
    Diapositivas.Add(new Diapositiva("Guts", "Personaje principal de Berserk", "Sprites/Guts"));

    LoadDiapositivas();
    Debug.Log(Input.touchCount);

}

// Update is called once per frame
void Update () {

    Debug.Log(Input.touchCount);

    if (Application.platform == RuntimePlatform.Android) {

        if(Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            float middleScreen = Screen.width / 2;

            if(touch.position.x < middleScreen && touch.phase == TouchPhase.Began)
            {


                Left();

            }

            else if (touch.position.x > middleScreen && touch.phase == TouchPhase.Began)
            {

                Right();
            }
        }

    }



}

}
unity3d
1个回答
0
投票

使用Unity remote 5并不意味着您正在使用移动设备。只是第二个触摸屏。所有条件都将与您的桌面相同。甚至屏幕分辨率也与您当前的游戏视图窗口相同。因此,RuntimePlatform值应为Windows / OSX。

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