private void Update()
    {
        transform.position = camera.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, .8f, 10f);

        //Initialize variables
        int arraySize;

        obstructed  = false;
        hoverRegion = null;

        //Decide if obstructed by another building
        arraySize = Physics2D.OverlapCircleNonAlloc(transform.position - new Vector3(0f, 0.4f), 0.9f, results);
        for (int i = 0; i < arraySize; i++)
        {
            if (results[i].CompareTag("Tile"))
            {
                obstructed = true;
                break;
            }
        }

        //Decide if within a district
        arraySize = Physics2D.OverlapCircleNonAlloc(transform.position - new Vector3(0f, 1.28f), 0.01f, results);
        for (int i = 0; i < arraySize; i++)
        {
            if (results[i].CompareTag("District"))
            {
                DistrictRegion region = results[i].GetComponent <DistrictRegion>();
                hoverRegion = region;
                break;
            }
        }

        //Set text
        textMesh.color = Placeable && Affordable ? Color.white : Color.red;
        if (hoverRegion != null)
        {
            textMesh.SetText(string.Format("{0}\n${1}\n{2}%", hoverRegion.districtProperties.tileName, Cost, Mathf.FloorToInt(hoverRegion.districtProperties.traffic * 100)));
        }
        else
        {
            textMesh.SetText("Move within a district to purchase");
        }

        //Visibility
        bool visibility = HUDBuildCommand.GetBuildableStateGlobal() == BuildableState.Dragging;

        textMesh.enabled = visibility;
        foreach (SpriteRenderer renderer in spriteRenderers)
        {
            renderer.enabled = visibility;
        }
    }
Example #2
0
 public void Return()
 {
     held = false;
     transform.position = initialPosition;
     selected           = null;
 }
Example #3
0
 public void OnPointerDown(PointerEventData eventData)
 {
     held     = true;
     selected = this;
 }