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

43 lines
1.5 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;
2019-10-07 15:50:34 +00:00
protected GameController gameController;
protected void Awake() {
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
}
2019-10-05 09:48:36 +00:00
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 15:50:34 +00:00
if(gameController.blackHole != null) {
Camera.main.transform.position = new Vector3(gameController.blackHole.transform.position.x,
gameController.blackHole.transform.position.y,
Camera.main.transform.position.z);
}
2019-10-06 22:26:32 +00:00
}
2019-10-05 09:48:36 +00:00
}
}