void TileSelectionBehaviour() { m_hit = Physics2D.Raycast(m_cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); // Not checking if it is a WorldTile might cause bugs? try { m_hoveredObject = m_hit.collider.transform.parent.gameObject; } catch (Exception e) { /*PrintException(e);*/ return; } m_previousTile = m_currentTile; m_currentTile = m_tman.GetTile(m_hoveredObject.transform.position.x, m_hoveredObject.transform.position.y); if (!m_currentTile.selected) { m_currentTile.UpdateTIle(TileState.Hovered); } if (Input.GetMouseButtonUp(0)) { m_selectedObject = m_hoveredObject; HandleSelection(); } if (!m_previousTile.selected) { if (m_previousTile != m_currentTile) { m_previousTile.UpdateTIle(TileState.Default); } } }
void HandleSelection() { if (m_selectedObject.GetComponent <WorldTile>() != null) { m_currentTile.UpdateTIle(TileState.Selected); // Only one tile can be selected foreach (GameObject wt in m_tman.unsortedNodes) { if (wt.GetComponent <WorldTile>() != m_currentTile) { wt.GetComponent <WorldTile>().UpdateTIle(TileState.Default); } } return; } if (m_selectedObject.GetComponent <Building>() != null) { // If we are placing the building if (!m_selectedObject.GetComponent <Building>().isBuilded) { m_hoveredObject = m_tman.GetTile(m_hoveredObject.transform.position.x, m_hoveredObject.transform.position.y).gameObject; return; } m_selectedObject.GetComponent <Building>().Clicked(); return; } }
void TileSelectedBehaviour() { if (m_currentTile != null) { if (m_previousTile != m_currentTile) { if (!m_previousTile.selected) { m_previousTile.UpdateTIle(TileState.Default); } } if (!m_currentTile.selected) { m_currentTile.UpdateTIle(TileState.Hovered); } /*if (Input.GetMouseButtonUp(0)) * { * m_currentTile.UpdateTIle(TileState.Selected); * }*/ m_previousTile = m_currentTile; } }