Пример #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 worldPosition = ExampleUtils.ScreenToWorld(area.root, Input.mousePosition);

        worldPosition           = new Vector3(worldPosition.x, worldPosition.y, -1);
        this.transform.position = worldPosition;

        if (!Input.GetMouseButtonDown(0))
        {
            return;                                       // only destroy if we click
        }
        if (!area.grid.Contains(area.map[worldPosition]))
        {
            return;
        }

        Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
        Vector2 max = new Vector2(float.MinValue, float.MinValue);

        foreach (Vector2 point in polygon.points)
        {
            min.x = Mathf.Min(min.x, point.x);
            min.y = Mathf.Min(min.y, point.y);
            max.x = Mathf.Max(max.x, point.x);
            max.y = Mathf.Max(max.y, point.y);
        }

        for (float i = min.x; i < max.x; i += area.CellDimensions.x / 2f)
        {
            for (float j = min.y; j < max.y; j += area.CellDimensions.y / 2f)
            {
                Vector3 test = transform.position + new Vector3(i, j, 0);

                if (!polygon.OverlapPoint(test))
                {
                    continue;
                }

                FlatHexPoint point = area.map[test];
                if (area.grid.Contains(point) && area.grid[point] != null)
                {
                    Destroy(area.grid[point].gameObject);
                }
            }
        }

        Use();          // adds to cooldown
    }
Пример #2
0
    void Update()
    {
        if (!startPositionSet)
        {
            // user hasn't set the start point yet
            if (Input.GetMouseButtonDown(0))
            {
                startPoint = ExampleUtils.ScreenToWorld(area.root, Input.mousePosition);
                startPoint = new Vector3(startPoint.x, startPoint.y, -1);
                lineRenderer.SetPosition(0, startPoint);
                lineRenderer.enabled = true;
                startPositionSet     = true;
            }
        }
        else
        {
            Vector3 mouse = ExampleUtils.ScreenToWorld(area.root, Input.mousePosition);

            // fixed length lazor beam
            Vector3 delta = mouse - startPoint;
            delta = new Vector3(delta.x, delta.y, 0);

            endPoint = startPoint + delta.normalized * length;
            endPoint = new Vector3(endPoint.x, endPoint.y, -1);

            aBitLeft = Vector3.Cross(delta, Vector3.back).normalized;

            lineRenderer.SetPosition(1, endPoint);

            if (Input.GetMouseButtonDown(0) && !effect.activeSelf)
            {
                lineRenderer.enabled = false;

                TreatmentGUI.AddCooldown(type, cooldown);

                effect.SetActive(true);
                effect.transform.position = startPoint;
                iTween.MoveTo(effect, iTween.Hash("position", endPoint,
                                                  "time", 2f,
                                                  "easetype", iTween.EaseType.linear,
                                                  "oncompletetarget", this.gameObject,
                                                  "oncomplete", "ZapComplete"));
            }
        }

        if (effect.activeSelf)
        {
            FlatHexPoint testPos = area.map[effect.transform.position];
            if (area.grid[testPos] != null)
            {
                Destroy(area.grid[testPos].gameObject);
            }
            testPos = area.map[effect.transform.position + aBitLeft];
            if (area.grid[testPos] != null)
            {
                Destroy(area.grid[testPos].gameObject);
            }
            testPos = area.map[effect.transform.position - aBitLeft];
            if (area.grid[testPos] != null)
            {
                Destroy(area.grid[testPos].gameObject);
            }
            gameObject.audio.Play();
        }
    }