Search Unity

2D Point and Click games

Discussion in '2D' started by colonhel, Jan 26, 2015.

  1. colonhel

    colonhel

    Joined:
    Jan 24, 2015
    Posts:
    2
    So im new to unity and wanted to ask some basic stuffs. For example if i wanted to create a basic 2D game that would let players click on objects on flat 2d space and images (something like hidden objects game), what would be the right way to detect that an object has been clicked?

    a. Place individual scripts on each clickable objects?
    b. Use raycast

    and any tips and workflow resources to making a type of this game is greatly appreciated.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    I'd go with raycast, or rather OverlapPoint. Something like this:
    Code (CSharp):
    1.             Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    2.  
    3.             Collider2D hitCol = Physics2D.OverlapPoint(mousePos);