Input.touchCount not working

Hello, I am new to Unity, but i was following a tutorial about making a simple Android game and something is not working right for me.

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

public class BallControl : MonoBehaviour
{
    public float power = 10f;
    public float maxDrag = 5f;
    public Rigidbody2D rb;
   
    void Update()
    {
        if(Input.touchCount > 0)
        {
            Debug.Log("works");
        }
    }
}

I have this really simple code but it never seems to reach inside of the if statement. I’ve tried putting Debug.Log outside the if, and it worked.
The script is attached properly.
There is no error, no warning or anything it simply doesn’t work, I will appreciate any help.

How are you testing your code? Note that you won’t get any touch input in the editor by default unless you actually have a touch screen on your computer.

To test touch input, you’ll either have to build and test on a device with a touch screen, use the Device Simulator which has limited touch emulation (especially no multitouch), use the Unity Remote to send touch input form a mobile device to the editor, or use the Unity UI event system, which can handle both mouse and touch input with the same code.

1 Like

Thanks a lot! I used the Device Simulator as you mentioned and this is what i was looking for. I didn’t know that it won’t work in the editor.