Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Vector3 firstPoint;
- private Vector3 secondPoint;
- void Update() {
- if(Input.GetMouseButtonDown(0)) {
- firstPoint = Input.mousePosition;
- }
- if(Input.GetMouseButton(0)) {
- secondPoint = Input.mousePosition;
- }
- if(Input.GetMouseButtonUp(0)) {
- Rect screenRectAngle = new Rect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
- foreach(GameObject unit in GameObject.FindGameObjectsWithTag("Unit")) {
- Vector3 screenSpacePos = Camera.main.WorldToScreenPoint(unit.transform.position);
- if(screenRectAngle.Contains(screenSpacePos)) {
- unitsSelected.Add(unit.GetComponent<UnitController>());
- print(unit.name + " selected.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement