Ejemplo n.º 1
0
    /*(random generation)waypoint functions*/
    private triggerWaypoint createWaypoint(int positionX, int positionY, mapGfx mapGfx, triggerWaypoint connectWith, int identification)
    {
        GameObject newWaypoint = new GameObject("waypoint " + identification);

        triggerWaypoint triggerWaypoint = newWaypoint.AddComponent <triggerWaypoint>();

        newWaypoint.transform.position = new Vector3(positionX, positionY);

        mapGfx.addGameObject(newWaypoint, "waypoint");

        if (connectWith != null)
        {
            triggerWaypoint.nextWaypoint = connectWith;
        }

        return(triggerWaypoint);
    }
    /*(random generation)waypoint functions*/
    private waypoint createWaypoint(int positionX, int positionY, mapGfx mapGfx, waypoint connectWith, int identification)
    {
        GameObject newWaypoint = new GameObject("waypoint " + identification);

        waypoint waypoint = newWaypoint.AddComponent <waypoint>();

        BoxCollider2D boxCollider2D = newWaypoint.AddComponent <BoxCollider2D>();

        boxCollider2D.size = new Vector2(0.32f, 0.32f);

        newWaypoint.transform.position = new Vector3(positionX, positionY);

        mapGfx.addGameObject(newWaypoint, "waypoint");

        if (connectWith != null)
        {
            connectWith.nextwaypoint = waypoint;
        }

        return(waypoint);
    }
Ejemplo n.º 3
0
    void Update()
    {
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (mousePosition.x < -0.5f || mousePosition.y < -0.5f)
        {
            mousePosition.x = -2;
            mousePosition.y = -2;
        }

        int mousePositionX = (int)(mousePosition.x + 0.5f);
        int mousePositionY = (int)(mousePosition.y + 0.5f);

        mapData mapData = gamemanager.instance.mapData;
        mapGfx  mapGfx  = gamemanager.instance.mapGfx;

        if (mapData == null || mapGfx == null)
        {
            return;
        }

        int tileOnMousePosition = mapData.getTileOnLayer(mousePositionX, mousePositionY, "tower");

        if (_buildTower == true && tileOnMousePosition != -1 && tileOnMousePosition != 1)
        {
            _mouseOverObject.SetActive(true);
            _mouseOverObject.transform.position = new Vector2(mousePositionX, mousePositionY);

            if (Input.GetMouseButtonDown(0) && _towers.ContainsKey(_towerTag))
            {
                mapData.setTileOnLayer(mousePositionX, mousePositionY, "tower", 1);
                GameObject newTower = Instantiate(_towers[_towerTag], new Vector2(mousePositionX, mousePositionY), Quaternion.identity) as GameObject;
                mapGfx.addGameObject(newTower, "tower");

                switch (_towerTag)
                {
                case "waterTower":
                    elementaryAffection.instance.waterLevel++;
                    break;

                case "fireTower":
                    elementaryAffection.instance.fireLevel++;
                    break;

                case "airTower":
                    elementaryAffection.instance.airLevel++;
                    break;

                case "earthTower":
                    elementaryAffection.instance.earthLevel++;
                    break;
                }

                elementaryAffection.instance.updateOnChange();
            }
        }
        else
        {
            _mouseOverObject.SetActive(false);
        }

        if (Input.GetMouseButtonDown(1))
        {
            _buildTower = false;
        }
    }