Hi i got this script:
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
private float dist;
private Vector3 v3OrgMouse;
private Plane plane = new Plane(Vector3.up, Vector3.zero);
void Start() {
dist = transform.position.z; // Distance camera is above map
}
void Update() {
if (Input.GetMouseButtonDown(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float dist;
plane.Raycast(ray, out dist);
v3OrgMouse = ray.GetPoint(dist);
v3OrgMouse.z = 0;
} else if (Input.GetMouseButton(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float dist;
plane.Raycast(ray, out dist);
Vector3 v3Pos = ray.GetPoint(dist);
v3Pos.z = 0;
transform.position -= (v3Pos - v3OrgMouse);
}
}
}
I need borders, i tried something like this:
if (transform.position.x >= -320 && transform.position.y <= 180 && transform.position.x <= 320 && transform.position.y >= -180) {
transform.position -= (v3Pos - v3OrgMouse);
}
But with my script i can move the camera for example to x = -321 and then i cant move anything anymore because the if statement is false.
I hope you have a solution.
Thx