Ejemplo n.º 1
0
    void Update()
    {
        if (MapUtilities.ClickCheck())                                                                      //If the mouse is positioned over a GameObject,
        {
            if (Input.GetMouseButtonDown(0))                                                                //If we left click,
            {
                SpawnObjAtPos();                                                                            //Spawn 'ObjectForSpawning' at the mouse's current position.
            }
            if (Input.GetMouseButton(1))                                                                    //If we right click,
            {
                transform.Translate(Input.GetAxis("Mouse X") * -0.4F, Input.GetAxis("Mouse Y") * -0.4F, 0); //Move the camera.
            }
        }

        Camera.main.orthographicSize += MapZoom(); //Sets the field of view of the camera. See the method 'MapZoom' for more info.

        mapZoom.current = Camera.main.orthographicSize;

        #region Set Camera and Map Bounds
        _camera.Center               = Camera.main.transform.position;
        _camera.Extents              = Camera.main.OrthographicBounds().extents;
        _camera._Sides.top.length    = _camera.Center.y + _camera.Extents.y;
        _camera._Sides.bottom.length = _camera.Center.y - _camera.Extents.y;
        _camera._Sides.right.length  = _camera.Center.x + _camera.Extents.x;
        _camera._Sides.left.length   = _camera.Center.x - _camera.Extents.x;

        map._Sides.top.length    = map._Renderer.bounds.max.y;
        map._Sides.bottom.length = map._Renderer.bounds.min.y;
        map._Sides.right.length  = map._Renderer.bounds.max.x;
        map._Sides.left.length   = map._Renderer.bounds.min.x;
        #endregion

        transform.position = CameraPosition(); //Set the position of this GameObject to that of the Vector3 '_position' put out by the method 'CameraPosition()'.

        //The bounds MUST be set before the camera position is set - the above two lines MUST be executed in the order they're currently in.
        //DO NOT swap them around, or you will end up being able to drag the camera outside of the map's bounds, resulting in really odd behaviour concerning the camera and the map.
        //Do so at your peril.

        modX = modXTimes * Camera.main.orthographicSize; //modX increases or reduces the amount that the camera can scroll horizontally at all zoom levels. Change 'modXTimes' to alter this.
    }