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

Touch / Mouse Input on GameObjects in certain order!

Discussion in 'Scripting' started by FRANKIEonPC, Jul 12, 2014.

  1. FRANKIEonPC

    FRANKIEonPC

    Joined:
    Jun 30, 2014
    Posts:
    31
    Hi,

    I have 4 GameObjects on the screen, and want to force the user to touch them in a certain order. I am not sure how to do this as the GameObjects are generated at runtime. Do I need to generate tags for them at runtime perhaps?

    Also, is there an easy way to emulate a single touch on the screen with left mouse click input for ease of development. Don't need multi-touch.

    Thanks!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    Is it always 4 objects? (or could be more or less too?)

    Could add them to list or array (in correct order) and then check which item was clicked..
    (for example, check if the last item was clicked (with raycast), then destroy it and remove it from the list..repeat that for next object..)

    Input.GetMouseButton(0) works as single touch also (same for OnMouseDown()).
     
  3. FRANKIEonPC

    FRANKIEonPC

    Joined:
    Jun 30, 2014
    Posts:
    31
    It's a near infinite list of objects that appear, all are named using an array z1, z2, z3 etc. so I need some way of checking that z1 is touched then z2, then z3 etc. etc.
     
  4. FRANKIEonPC

    FRANKIEonPC

    Joined:
    Jun 30, 2014
    Posts:
    31
    Does anybody know?
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    From raycast you can get game object name: hit.transform.name

    then you could have separate counter that you increment everytime you click correct object..
    so
    lets say counter = 1
    if you click any object: check if hit.transform.name == "z"+counter