Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Get touches amount with enhanced touch

Discussion in 'Input System' started by XeLLLeR, May 14, 2022.

  1. XeLLLeR

    XeLLLeR

    Joined:
    Dec 5, 2020
    Posts:
    30
    So I want to get amount of touches that currently press the touchscreen using EnhancedTouch. I use this namespaces:
    Code (CSharp):
    1. using UnityEngine.InputSystem.EnhancedTouch;
    2. using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
    In Awake method I enable TouchSimulation:
    Code (CSharp):
    1. TouchSimulation.Enable();
    After that I just check touches amount with some variants, but always get 0 for some reasons. The variants that I've tried:
    Code (CSharp):
    1. print("Touches amount " + Touch.fingers.Count);
    2. print("Touches amount " + Touch.activeTouches.Count);
    3. print("Touches amount " + Touch.activeFingers.Count);
    UPD: I've just forgot to use EnhancedTouchSupport
     
    Last edited: May 16, 2022
  2. onure_unity

    onure_unity

    Joined:
    Sep 7, 2023
    Posts:
    1
    I can't make this work. In editor play mode, It's still printing zero for touch count.

    Were you able to find a better solution?

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
    4.         UnityEngine.InputSystem.EnhancedTouch.TouchSimulation.Enable();
    5.     }
    6.  
    7.     void Update()
    8.     {
    9.         print(UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches.Count);
    10.     }
    11.  
     
  3. xiennastudio

    xiennastudio

    Joined:
    Aug 2, 2023
    Posts:
    19
    From what I have check, to test in the Editor, open the Input Debugger from Window > Analysis > Input Debugger.
    Then enable this:
    upload_2023-9-13_15-43-56.png

    Alternative way, if you don't want to use Input Debugger, you can use Simulator.
    upload_2023-9-13_15-39-5.png