Search Unity

Drag sprite through a specific area

Discussion in 'Scripting' started by fazraz, Feb 15, 2018.

  1. fazraz

    fazraz

    Joined:
    Feb 27, 2015
    Posts:
    14
    Hi all,

    I'm looking to create a very simple 2D gear stick which is draggable into the correct gear positions (1, 2, 3, 4 and 5). Here is an image of what I mean:

    Gear 1 - https://imgur.com/GmcIvf1
    Gear 2 - https://imgur.com/Fj3KD4W
    Gear 3 - https://imgur.com/q5zlhbf

    etc.

    I have a script which allows the red 'gear stick' to be draggable, however I don't know how to keep it within the bounds of the gear guide (the grey lines).

    I've tried using collision boxes but can't get the red gear stick to stay within the bounds. I understand the logic is to lock the X axis until the stick reaches the junction, and then release the Y axis but this didn't work well for me.

    Many thanks,
    Farid
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    There's no need to double post, please.