There is a Rect from which mouse clicks are taken, limited by the coordinates of the camera anchors.

bounds = new Rect(upLeft.transform.position.x, downRight.transform.position.y, downRight.transform.position.x - upLeft.transform.position.x, upLeft.transform.position.y - downRight.transform.position.y); if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition)) { Began(Input.mousePosition); } 

How to add areas to it - exceptions? Suppose it is necessary that from this Rect the upper right corner, for example, the upper right corner was inactive + the lower right corner was inactive. I think it should look like this

 public List <Rect> AreaException; AreaException.add(new Rect (0,0, 30,30)); AreaException.add(new Rect (50,50,30,30)); 

But what to do next? It seems like they need to go through foreach and somehow remove the coordinates belonging to them from the original Rect. How to do this?

    1 answer 1

    I would declare a class based on a list in which I described the verification method:

     public class AreaExceptions : List<Rect> { public bool Contains(Vector3 point) { foreach(var item in this) { if (item.Contains(point) return true; } return false; } } 

    Well, the code will be:

     bounds = new Rect(upLeft.transform.position.x, downRight.transform.position.y, downRight.transform.position.x - upLeft.transform.position.x, upLeft.transform.position.y - downRight.transform.position.y); var exepts = new AreaExceptions(); exepts.Add(new Rect (0,0, 30,30)); exepts.Add(new Rect (50,50,30,30)); if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition) && ! exepts.Contains(Input.mousePosition)) { Began(Input.mousePosition); } 

    The only thing - the coordinates need to be recalculated from relative to the coordinates of the source rectangle

    • How to count this? - Dmitrii
    • one
      @Dmitrii, well, your exclusion zones exist inside the tracked rectangle, but the coordinates in the exceptions in my proposed solution are specified in absolute (relative to the rectangle) coordinates. exepts.Add(new Rect (0,0, bounds.x+30,bounds.y+30)); - something like this. - eastwing
    • one
      By the way, you can expand the List <Rect> - eastwing