void Update() { for (int i = 0; i < 2; i++) { if (Selector.GetComponent <BoxCollider2D>().bounds.Contains(U2[i].gameObject.transform.position) && !U.Contains(U2[i])) { Debug.Log('1'); //selection_script.GetComponent<Selection>().unit = 0; //container.GetComponent<VariableStoreage>().selected_units.Add(gameObject); U.Add(U2[i]); U2[i].transform.Find("Circle").GetComponent <Renderer>().enabled = true; } } if (Input.GetMouseButtonDown(0) && U.Count != 0) { Debug.Log('1'); U.Clear(); for (int i = 0; i < 2; i++) { U2[i].transform.Find("Circle").GetComponent <Renderer>().enabled = false; } } //U[0].Attack(GameObject.Find("Enemy (1)")); if (Input.GetButtonDown("Fire2")) { Camera camera = GameObject.Find("Main Camera").GetComponent <Camera>(); Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { string name = hit.collider.gameObject.tag; switch (name) { case "Enemy": foreach (NewBehaviourScript kek in U) { kek.Attack(hit.collider.gameObject); kek.aim = hit.collider.gameObject; } break; case "YourUnit": if (!Input.GetButton("Left Ctrl")) { U = new List <NewBehaviourScript> { hit.collider.gameObject.GetComponent <NewBehaviourScript>() } } ; else if (U.Contains(hit.collider.gameObject.GetComponent <NewBehaviourScript>())) { U.Remove(hit.collider.gameObject.GetComponent <NewBehaviourScript>()); } else { U.Add(hit.collider.gameObject.GetComponent <NewBehaviourScript>()); } break; } } else { Vector2 position = new Vector2(Mathf.FloorToInt(Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)).x), Mathf.FloorToInt((Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y))).y)); if (path.PosToMove(position)) { U.Sort(delegate(NewBehaviourScript a, NewBehaviourScript b) { return((a.position() - new Vector2(position.x, position.y)).magnitude.CompareTo((b.position() - new Vector2(position.x, position.y)).magnitude)); }); List <Vector2> positions = path.ClosesedFreePoints(new Point(Mathf.FloorToInt(position.x), Mathf.FloorToInt(position.y), 0, 0, null), U.Count); List <Vector2> pth = new List <Vector2> { }; for (int i = 0; i < U.Count; ++i) { pth = path.Path(U[i].transform.position, positions[i]); //Debug.Log(pth.Count); // for (int j = 0; j < pth.Count; ++j) // Debug.Log(i + ": " + j + " " + pth[j]); U[i].setPath(pth); } } } } }