private void OnMouseDrag() { Vector2 mousePos = (Vector2)main.ScreenToWorldPoint(Input.mousePosition); Vector2 direction = (mousePos - (Vector2)this.transform.position); rb.velocity = direction.normalized * dragSpeed * direction.magnitude; Collider2D collider = Physics2D.OverlapPoint(mousePos, tileMask); if (collider) { TussleManager tussle = TussleManager.instance; Tile hoveredTile = Tile.hoveredTile; if (Tile.hoveredTile != null) { if (hoveredTile.HasUnit()) { Tile.hoveredTile.GetComponent <SpriteRenderer>().color = Color.clear; } else if (tussle.ColumnInRange(hoveredTile.xIndex)) { Tile.hoveredTile.GetComponent <SpriteRenderer>().color = new Color(0, 1, 0, .5f); } } Tile tile = collider.GetComponent <Tile>(); if (tussle.ColumnInRange(tile.xIndex)) { if (!tile.HasUnit()) { tile.GetComponent <SpriteRenderer>().color = new Color(0, 1, 0, .25f); Tile.hoveredTile = tile; } } } }
void Awake() { if (instance != null) { DestroyImmediate(gameObject); return; } instance = this; raritySprites = temp_raritySprites; }
private void OnMouseUp() { Vector2 mousePos = (Vector2)main.ScreenToWorldPoint(Input.mousePosition); dragging = false; Collider2D collider = Physics2D.OverlapPoint(mousePos, tileMask); if (collider) { // Place the recruit onto the map Tile tile = collider.GetComponent <Tile>(); TussleManager tussle = TussleManager.instance; if (tussle.ColumnInRange(tile.xIndex)) { if (!tile.HasUnit()) { tussle.AttemptBuyRecruit(this, tile); } } } }