44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
public Transform cam;
|
|
public float sensitivity;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
private Vector2 mouseStartPos = Vector2.zero;
|
|
private Vector3 cameraStartPos = Vector2.zero;
|
|
public bool moving = false;
|
|
public void OnMouseDown(BaseEventData e){
|
|
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
|
mouseStartPos = ped.position;
|
|
cameraStartPos = cam.transform.position;
|
|
moving=true;
|
|
}
|
|
public void OnMouseUp(BaseEventData e){
|
|
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
|
moving=false;
|
|
}
|
|
public void OnMouseMove(BaseEventData e){
|
|
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
|
if(moving && !Selector.isMovingBuilding){
|
|
Vector3 offset = (mouseStartPos-ped.position) * sensitivity;
|
|
cam.transform.position = cameraStartPos + new Vector3(offset.x,0,offset.y);
|
|
}
|
|
}
|
|
|
|
|
|
}
|