I've tried to use this common script for camera movement, but I just can't seem to get it to move vertically.
using UnityEngine;
using System.Collections;
public class DragCamera : MonoBehaviour
{
public float dragSpeed = 2;
private Vector3 dragOrigin;
public bool cameraDragging = true;
public float outerLeft = -10f;
public float outerRight = 10f;
void Update()
{
Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
float left = Screen.width * 0.2f;
float right = Screen.width - (Screen.width * 0.2f);
if(mousePosition.x < left)
{
cameraDragging = true;
}
else if(mousePosition.x > right)
{
cameraDragging = true;
}
if (cameraDragging) {
if (Input.GetMouseButtonDown(0))
{
dragOrigin = Input.mousePosition;
return;
}
if (!Input.GetMouseButton(0)) return;
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
Vector3 move = new Vector3(pos.x * dragSpeed, 0, 0);
if (move.x > 0f)
{
if(this.transform.position.x < outerRight)
{
transform.Translate(move, Space.World);
}
}
else{
if(this.transform.position.x > outerLeft)
{
transform.Translate(move, Space.World);
}
}
}
}
}
Tried doubling it, but using the y axis in place of the x axis in the same places, as well as changing left and right to up and down. But it always just moves left and right still.
The reason I use this script is because the person that made it says that it creates camera boundaries, which it indeed does, but it won't be of much use until I can get the y axis in there.
Also made Screen.width instances into Screen.height instead, still didn't work.
I've tried for at least two hours to get it to work, but I'm at a bit of a loss, Araph, any advice?