Source code for Unity tutorial on how to select units within rectangle. Notice that the code is not exactly as in the tutorial because I've learned one or two things but the idea is the same. The main difference you should change is that border of the selection square has to be 2 pixels wide, or you will see some flickering.
YouTube video showing the result:
Link to the tutorial: https://www.habrador.com/tutorials/select-units-within-rectangle/
If you also want to highlight the units you selected with some rectangle around it, the idea is basically the same. This is a good tutorial on the topic: https://www.youtube.com/watch?v=2Tgqr1_ajqE