A 2D Farming RPG
This is just a simple 2D farming RPG game
Loading...
Searching...
No Matches
SwitchConfineBoundingShape.cs
Go to the documentation of this file.
1using UnityEngine;
2using Cinemachine;
3
8public class SwitchConfineBoundingShape : MonoBehaviour
9{
10
14 private void OnEnable()
15 {
16 EventHandler.AfterSceneLoadEvent += SwitchBoundingShape;
17 }
18
22 private void OnDisable()
23 {
24 EventHandler.AfterSceneLoadEvent -= SwitchBoundingShape;
25 }
26
30 private void SwitchBoundingShape()
31 {
32 // Get the polygon colider on the 'boundsconfiner' gameobject which is used by Cinemachine to prevent the camera going beyond the screen edges.
33 PolygonCollider2D polygonCollider2D = GameObject.FindGameObjectWithTag(Tags.BoundsConfiner).GetComponent<PolygonCollider2D>();
34
35 CinemachineConfiner cinemachineConfiner = GetComponent<CinemachineConfiner>();
36
37 cinemachineConfiner.m_BoundingShape2D = polygonCollider2D;
38
39 // Since the confiner bounds have changed need to call this to clear the cache.
40 cinemachineConfiner.InvalidatePathCache();
41 }
42
43}
This class will confine the camera so that it won't go beyond the boundaries.
void OnDisable()
Unsubscribe from the AfterSceneLoadEvent event.
void SwitchBoundingShape()
Switch the collider that cinemachine uses to define the edges of the screen.
void OnEnable()
Subscribe to the AfterSceneLoadEvent event.
This class will have Tags values.
Definition: Tags.cs:5
const string BoundsConfiner
Definition: Tags.cs:6