Search Unity

Placement Zones

Discussion in '2D' started by Expediter, Feb 28, 2015.

  1. Expediter

    Expediter

    Joined:
    Feb 25, 2015
    Posts:
    2
    Hello everyone, I am hoping someone can give me some direction. I am learning unity at the moment and my knowledge at the moment is not enough to solve this problem in an elegant fashion.

    i am playing around with unity and am trying to make card placement zones in a scene. At the moment I have 3 types of cards in the scene, these cards can be dragged around the scene from a "Hand zone". I would like to drag these cards from my "hand" to the board and place them in their proper zones. If the card is being placed in the wrong zone or not any zone at all then it will snap back to the "hand" zone.

    I have attempted to make zones by dragging in sprites , giving it a 2d box collider, giving the cards 2D box colliders and then using Physics2D.OverlapAreaAll to determine if I have hit the zone when onmouseup() is called. My issue is this feels clunky, like I am doing it wrong.

    Could someone give me ideas / psudocode to accomplish this? just a high level guide with general steps.

    side note, I am finding it hard to modularize my code, I am new to OOP and find myself writing most of my code in one script. Does anyone have advice for how to modularize your game code? Tips on when to break things up how or much code in a script is too much in one script, my "cardController" script continues to get larger and larger and I am finding it difficult to break it up. should mouse movement of an object be handled by 1 script and thencollision detection handles by another , or just all in one.

    one last thing Physics2d.OverlapAreaNonAlloc refuses to return anything where Physics2D.OverlapAreaAll does using the same point A and point B in the same scene , any clue as to why ?

    Thanks in advance.
     
  2. Deleted User

    Deleted User

    Guest

    For Physics2d.OverlapAreaNonAlloc, were you checking the returned int or the results.Length?