Search Unity

what is the difference between Input.Touches[0] and Input.GetTouch(0) ?

Discussion in 'Scripting' started by MrZzzero, Sep 2, 2019.

  1. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    and whats the uses of each one ?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    touches:
    https://docs.unity3d.com/ScriptReference/Input-touches.html

    gettouch:
    https://docs.unity3d.com/ScriptReference/Input.GetTouch.html

    Theyr'e effectively the same thing... main difference being that 'touches' will allocate an array on the heap, where as GetTouch won't.

    'touches' is useful if you intend to save off the touch collection. GetTouch is useful if you want to check a specific touch. Honestly you likely don't need the 'touches' property, unless there's something about it I'm missing (and isn't obvious in the documentation).
     
    AustinSyu and MrZzzero like this.
  3. MrZzzero

    MrZzzero

    Joined:
    Dec 9, 2016
    Posts:
    67
    thank you for that good explanation