Advertisement
Guest User

Untitled

a guest
Feb 11th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. private Vector3 firstPoint;
  2.     private Vector3 secondPoint;
  3.  
  4.     void Update() {
  5.  
  6.         if(Input.GetMouseButtonDown(0)) {
  7.             firstPoint = Input.mousePosition;
  8.         }
  9.  
  10.         if(Input.GetMouseButton(0)) {
  11.             secondPoint = Input.mousePosition;
  12.         }
  13.  
  14.         if(Input.GetMouseButtonUp(0)) {
  15.             Rect screenRectAngle = new Rect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
  16.             foreach(GameObject unit in GameObject.FindGameObjectsWithTag("Unit")) {
  17.                 Vector3 screenSpacePos = Camera.main.WorldToScreenPoint(unit.transform.position);
  18.        
  19.                 if(screenRectAngle.Contains(screenSpacePos)) {
  20.                     unitsSelected.Add(unit.GetComponent<UnitController>());
  21.                     print(unit.name + " selected.");
  22.                 }
  23.             }
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement