2025-02-27 21:35:24 +08:00

53 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using System;
public class CameraControl : MonoBehaviour
{
private CinemachineConfiner2D confiner2D;
public CinemachineImpulseSource impulseSource;
public VoidEventSO cameraShakeEvent;
private void Awake()
{
confiner2D = GetComponent<CinemachineConfiner2D>();
}
private void OnEnable()
{
cameraShakeEvent.OnEventRaised += OnCameraShakeEvent;
}
private void OnDisable()
{
cameraShakeEvent.OnEventRaised -= OnCameraShakeEvent;
}
private void OnCameraShakeEvent()
{
impulseSource.GenerateImpulse();
}
private void Start()
{
GetNewCameraBounds();
}
private void GetNewCameraBounds()
{
var obj = GameObject.FindGameObjectWithTag("Bounds");
if(obj == null)
{
return;
}
confiner2D.m_BoundingShape2D = obj.GetComponent<Collider2D>();
confiner2D.InvalidateCache();
}
}