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. Dismiss Notice

what is the different between "input.touches.Legnth" and "input.touch"

Discussion in 'Scripting' started by fangye_Studio, Aug 10, 2014.

  1. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    hi guys
    need a help to explain the input.touches for me more ..
    I am learning coding for touchscreen . I just find the doc said "input.touches" represent a list of all touches at the last frame , then input.touches(i) should be the object represents each touch right ?
    then I found another code input.touchCount , this one also can tell me how many touches in the last frame , it looks like same result as the input.touches.Length. then I also find some sample code that they use input.Gettouch(i) to represent each touch .

    so my question is what the different function about these touch code when we use it in real work ?
    input.touches.Length / input.touchCount
    input.touches(i)/input.Gettouch(i)
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    If you use Input.touches then it has to allocate temporary variables for the array; if you use Input.touchCount then it doesn't. So you can use that to avoid checking input in more detail if there aren't any touches.

    --Eric
     
  3. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    ok~, thanks~ :)