Beispiel #1
0
    void Update()
    {
        MapNode fingerPos =
            MapHandler.GetMapNode(GameUtil.ToGameUnitInt(
                                      Camera.main.ScreenToWorldPoint(Input.mousePosition)));
        MapNode characterPos = MapHandler.GetMapNode(character.GetPositionInt());

        Assert.IsNotNull(characterPos);

        if (fingerPos != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (checkTouchStatus(fingerPos) == TouchStatus.drawing)
                {
                    character.ResetPath();
                    // Path finding
                    List <Vector2> path = MapHandler.FindPath(characterPos, fingerPos);
                    Assert.IsNotNull(path);
                    character.SetPath(path);
                    character.SetEndCircle(fingerPos);
                }
                else if (checkTouchStatus(fingerPos) == TouchStatus.dragging)
                {
                    // do nothing
                }
            }
            if (Input.GetMouseButton(0))
            {
                character.UpdatePath(fingerPos);
            }
        }
    }
Beispiel #2
0
    public void FindNextTarget()
    {
        movingPath.Reset();
        MapNode curNode  = GetPosition();
        MapNode nextNode = curNode;

        while (nextNode == null || nextNode == curNode || nextNode.IsWall())
        {
            int x = Random.Range(bornX - wanderDistance, bornX + wanderDistance);
            int y = Random.Range(bornY - wanderDistance, bornY + wanderDistance);
            nextNode = MapHandler.GetMapNode(x, y);
        }
        List <Vector2> path = MapHandler.FindPath(curNode, nextNode);

        SetPath(path);
    }