private void Update() { //If the left mouse button is clicked. if (!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0)) { //Get the mouse position on the screen and send a raycast into the game world from that position. Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D[] hit = Physics2D.RaycastAll(worldPoint, Vector2.zero); //If something was hit, the RaycastHit2D.collider will not be null. if (hit.Length > 0) { for (int j = hit.Length - 1; j >= 0; j--) { RaycastHit2D i = hit[j]; if (i.transform.gameObject.layer == LayerMask.NameToLayer("City")) { City city = UnityUtility.GetSafeComponent <City>(i.transform.parent.parent.gameObject); cityUI.SetCity(city); SelectedMarket = city; } if (i.transform.gameObject.layer == LayerMask.NameToLayer("Unit")) { Unit unit = UnityUtility.GetSafeComponent <Unit>(i.transform.gameObject); unitUI.SetUnit(unit); } } } } }
private void InitializeCitys() { // 도시들 초기화 citys = new Dictionary <string, City>(); cityUIs = new Dictionary <City, CityUI>(); destroyedCitys = new Progress(cityDatas.Count); foreach (var cityData in cityDatas) { string name = cityData.name; City city = new City(cityData); city.OnDestroy += OnDestroyCity; city.OnRecovery += OnRecoveryCity; citys.Add(name, city); CityUI cityUI = cityData.cityUI; cityUIs.Add(city, cityUI); cityUI.SetCity(city); } }