0
votes

I am using Unity remote 5 and i am trying to make a simple image gallery, if you press on the right of the screen it moves forward and if you press on the left it moves bakcwards...

The problem is that not a single touch is being registered, even using "Debug.Log(Input.touchCount);" gives me no input whatsoever and i dont know what is wrong.

Here is the code:

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();
            }
        }

    }



}

}
1
I have noticed that if i remove this line: if (Application.platform == RuntimePlatform.Android) {} it works... but i added that to identify what platform is running on... i don't get why adding that "if" breaks everything. - Hagogs
Yes, the problem is causing by this line. But the real problem is because you are using Unity Remote 5. So the Application.platform actually returns your Unity Editor. Further explanation and solutions here. - ming060

1 Answers

0
votes

Using Unity remote 5 dosen't means you are using mobile device. It just a second screen with touch . All the conditions would be the same as your desktop. Even the screen resolution is the same as your current Game view window . So RuntimePlatform value should be Windows/OSX.