it only scrolls left, i cant get it to scroll right until I scroll it to the left. When trying to scoll up, it jumps up a scree instead of scrolling. Cant scroll down until after the screen jumped up but it doesnt scroll down it jumps down too. The only scrolling is left and right.
Would be nice if up and down scrolling will work too.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour
{
public float panSpeed = 10f; //how fast the screen moves when mouse is at an edge
public float panBorderThickness = 10f;
public Vector2 panLimit;
float inputX, inputZ;
void Update() //the mouse works in this section, and only the left and right keys works
//put cursor at border of the map to scroll the screen
{
Vector3 pos = transform.position;
{ if (Input.GetKey("w") || Input.mousePosition.y >= Screen.height - panBorderThickness)
pos.z += panSpeed * Time.deltaTime;
}
{
if (Input.GetKey("s") || Input.mousePosition.y <= panBorderThickness)
pos.z -= panSpeed * Time.deltaTime;
}
{if (Input.GetKey("d") || Input.mousePosition.x >= Screen.width - panBorderThickness) //moves screen right
pos.x += panSpeed* Time.deltaTime;
}
{
if (Input.GetKey("a") || Input.mousePosition.x <= panBorderThickness) //moves left with the key...
//...and when mouse cursor is at the left edge
pos.x -= panSpeed* Time.deltaTime;
}
//these next two lines stops the screen from moving when reaching the border...
//...limit. Set that in the inspector.
//for some reason, its starting my screen away form where I want it at the fitst limit
pos.x = Mathf.Clamp(pos.x, -panLimit.x, panLimit.x);
pos.z = Mathf.Clamp(pos.z, -panLimit.y, panLimit.y);
transform.position = pos;
}
}