1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-29 03:24:30 +00:00
gravity-fusion/Assets/Components/CameraPan.cs

33 lines
1.1 KiB
C#
Raw Normal View History

2019-10-05 09:48:36 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Camera))]
2019-10-05 18:41:07 +00:00
public class CameraPan : MonoBehaviour
2019-10-05 09:48:36 +00:00
{
2019-10-05 18:41:07 +00:00
public string axisName;
2019-10-05 09:48:36 +00:00
protected Vector3? lastMousePosition;
private void Start() {
lastMousePosition = null;
}
private void Update() {
2019-10-05 18:41:07 +00:00
bool panIsPressed = Input.GetAxisRaw(axisName) != 0f;
2019-10-05 09:48:36 +00:00
Vector3? currentMousePosition = null;
2019-10-05 18:41:07 +00:00
if(panIsPressed) {
2019-10-07 11:44:26 +00:00
currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
2019-10-05 09:48:36 +00:00
if(lastMousePosition.HasValue) {
Vector3 positionDelta = lastMousePosition.Value - currentMousePosition.Value;
2019-10-07 11:44:26 +00:00
Camera.main.transform.position += positionDelta;
currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
2019-10-05 09:48:36 +00:00
}
}
lastMousePosition = currentMousePosition;
2019-10-06 22:26:32 +00:00
if(Input.GetAxisRaw("ResetCamera") > 0) {
2019-10-07 11:44:26 +00:00
Camera.main.transform.position = new Vector3(0, 0, Camera.main.transform.position.z);
2019-10-06 22:26:32 +00:00
}
2019-10-05 09:48:36 +00:00
}
}