void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //get the tile currently being clicked on
            var p  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var p2 = new Vector3(p.x, p.y, 0f);
            var p3 = map.WorldToCell(p2);

            if (map.GetTile(p3) == null)
            {
                //return if it's null
                return;
            }


            //if the clicked tile is a buildzone and there is a module currently selected
            if (buildZone.ContainsKey(p3) && currentlySelected != null)
            {
                var module = buildZone[p3].GetComponent <ModuleObject>().module;

                //if the module below is building zone
                if (module == buildingZone)
                {
                    //if selection tiles is not null i.e. if some buildzone is selected
                    if (selectionTile != null)
                    {
                        Destroy(selectionTile.gameObject);
                        //if the current click is on the selection tile
                        if (map.WorldToCell(selectionTile.transform.position) == p3)
                        {
                            //add the new module at the selected tile
                            var newModule = GenerateTile(currentlySelected, p3);

                            map.SetTile(p3, newModule.tile);

                            currentTiles.Remove(p3);
                            currentTiles.Add(p3, newModule.obj);

                            var g = buildZone[p3];
                            buildZone.Remove(p3);

                            Destroy(g);

                            GameEvents.RaiseOnModulePlaced(currentlySelected, p3);

                            currentlySelected = null;

                            //Update resources according to the new module


                            return;
                        }
                    }

                    //select this zone
                    var newSelectedTile = new GameObject(buildingZoneSelected.name);

                    newSelectedTile.transform.SetParent(map.transform);
                    newSelectedTile.transform.localRotation = Quaternion.identity;
                    newSelectedTile.transform.localPosition = map.CellToWorld(p3);

                    var s = newSelectedTile.AddComponent <SpriteRenderer>();
                    s.sprite       = buildingZoneSelected.moduleImage;
                    s.sortingOrder = 1;

                    var m = newSelectedTile.AddComponent <ModuleObject>();
                    m.module = buildingZoneSelected;

                    selectionTile = newSelectedTile;
                }
            }


            if (currentTiles.ContainsKey(p3))
            {
                UpgradeSystem.OpenModuleUpgradeMenu(currentTiles[p3].gameObject);
            }
        }
    }