SHARE
TWEET

Untitled

a guest Feb 11th, 2014 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top