57 lines
1.2 KiB
Plaintext
57 lines
1.2 KiB
Plaintext
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CounterCameraMover : MonoBehaviour
|
|
{
|
|
private Camera m_camera;
|
|
private Vector3 m_cameraLastPos;
|
|
|
|
[SerializeField]
|
|
private bool m_moveOnX = true;
|
|
[SerializeField]
|
|
private bool m_moveOnY = true;
|
|
[SerializeField]
|
|
private bool m_moveOnZ = false;
|
|
|
|
[SerializeField]
|
|
private float m_speedRatio = 1.0f;
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (m_camera == null)
|
|
{
|
|
m_camera = Camera.main;
|
|
m_cameraLastPos = m_camera.transform.position;
|
|
}
|
|
|
|
if (m_camera == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 cameraPos = m_camera.transform.position;
|
|
Vector3 delta = cameraPos - m_cameraLastPos;
|
|
OnCameraMove(delta);
|
|
m_cameraLastPos = cameraPos;
|
|
}
|
|
|
|
private void OnCameraMove(Vector3 delta)
|
|
{
|
|
if (!m_moveOnX)
|
|
{
|
|
delta.x = 0;
|
|
}
|
|
if (!m_moveOnY)
|
|
{
|
|
delta.y = 0;
|
|
}
|
|
if (!m_moveOnZ)
|
|
{
|
|
delta.z = 0;
|
|
}
|
|
transform.Translate(-delta * m_speedRatio);
|
|
}
|
|
}
|