Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     //if (viewDrag == null || (viewDrag && !viewDrag.isDragging)) {
     if (!GamePause.isPause())
     {
         if (target)
         {
             Vector3 point       = camera.WorldToViewportPoint(target.position);
             Vector3 delta       = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z));            //(new Vector3(0.5, 0.5, point.z));
             Vector3 destination = transform.position + delta;
             if (clampCamera != null)
             {
                 destination = clampCamera.clampDes(destination);
             }
             transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
         }
     }
 }
Exemplo n.º 2
0
    void LeftMouseDrag()
    {
        // From the Unity3D docs: "The z position is in world units from the camera."  In my case I'm using the y-axis as height
        // with my camera facing back down the y-axis.  You can ignore this when the camera is orthograhic.
        current_position.z = hit_position.z = camera_position.y;

        // Get direction of movement.  (Note: Don't normalize, the magnitude of change is going to be Vector3.Distance(current_position-hit_position)
        // anyways.
        Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);

        // Invert direction to that terrain appears to move with the mouse.
        direction = direction * -1;

        Vector3 position = camera_position + direction;

        if (clampCamera != null)
        {
            position = clampCamera.clampDes(position);
        }

        transform.position = position;
    }