49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BUT
|
|
{
|
|
/* Handle Camera's rotation */
|
|
public class CameraMovementOrbitalAlt : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
bool orbitSurY;
|
|
|
|
[SerializeField]
|
|
float m_XSpeedRotation;
|
|
|
|
[SerializeField]
|
|
float m_YSpeedRotation;
|
|
|
|
Vector3 m_CurrentRotation;
|
|
|
|
[SerializeField]
|
|
private Transform target;
|
|
|
|
private void Start()
|
|
{
|
|
// init rotation
|
|
m_CurrentRotation = transform.rotation.eulerAngles;
|
|
}
|
|
|
|
public void Scroll(InputAction.CallbackContext _context){
|
|
float value = _context.ReadValue<float>();
|
|
transform.position += value * transform.forward * Time.deltaTime;
|
|
}
|
|
|
|
public void Rotate(InputAction.CallbackContext _context)
|
|
{
|
|
m_CurrentRotation = _context.ReadValue<Vector2>();
|
|
|
|
m_CurrentRotation.x *= m_XSpeedRotation;
|
|
m_CurrentRotation.y *= m_YSpeedRotation;
|
|
|
|
|
|
transform.RotateAround(target.position, Vector3.up, m_CurrentRotation.x * Time.deltaTime);
|
|
if (orbitSurY) transform.RotateAround(target.position, Vector3.left, m_CurrentRotation.y * Time.deltaTime);
|
|
|
|
transform.up = Vector3.up;
|
|
}
|
|
}
|
|
}
|