Untitled
unknown
csharp
a year ago
1.9 kB
13
Indexable
public class PlanManager : MonoBehaviour
{
[SerializeField] private PlanAttributes[] plans = new PlanAttributes[2];
private float _changingParallaxValue;
private float _yOffset;
private ParallaxSystem[] _parallaxSystems;
private Player _player;
public static PlanManager Instance;
private void Awake()
{
#region Check
if (plans[0].planGO == null)
{
Debug.LogError("PlayerPlanPhysics: No plan was found.");
return;
}
//Must have exactly two plans
if(plans.Length != 2)
{
Debug.LogError("PlayerPlanPhysics: Plans array must contain exactly two elements.");
}
#endregion
//Get all references of colliders for each plan
foreach (var plan in plans)
{
plan.planColliders = plan.planGO.GetComponentsInChildren<Collider2D>();
}
//Get all parallax systems in the scene, even if they are inactive
_parallaxSystems = FindObjectsByType<ParallaxSystem>(FindObjectsInactive.Include, FindObjectsSortMode.None);
//Get the changing parallax value for all the game
_changingParallaxValue = ConstantGameValue.Instance.changingParallaxValue;
_yOffset = ConstantGameValue.Instance.YOffsetForPlan;
_player = Player.Instance;
if (_player == null)
{
Debug.LogError("PlanManager: Player instance not found.");
}
if (Instance != null)
{
Debug.LogError("PlanManager: 2 instances in one time.");
}
Instance = this;
}
private void Start()
{
_player.TransitionPlanChanged += ChangePlan;
}
private void OnDisable()
{
_player.TransitionPlanChanged -= ChangePlan;
}Editor is loading...
Leave a Comment