Wait for correct screen orientation
This commit is contained in:
@@ -20,6 +20,9 @@ namespace Minigames.DivingForPictures
|
||||
// Tap impulse system variables
|
||||
private float _tapImpulseStrength = 0f;
|
||||
private float _tapDirection = 0f;
|
||||
|
||||
// Initialization flag
|
||||
private bool _isInitialized = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -35,11 +38,53 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Register as default consumer for input
|
||||
InputManager.Instance?.SetDefaultConsumer(this);
|
||||
// Initialize target to current position
|
||||
_targetFingerX = transform.position.x;
|
||||
_isTouchActive = false;
|
||||
|
||||
// Find DivingGameManager and subscribe to its initialization event
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized += Initialize;
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
if (gameManager.GetType().GetField("_isGameInitialized",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance)?.GetValue(gameManager) is bool isInitialized && isInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[PlayerController] DivingGameManager not found. Initializing immediately.");
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the player controller when triggered by DivingGameManager
|
||||
/// </summary>
|
||||
private void Initialize()
|
||||
{
|
||||
if (_isInitialized) return;
|
||||
|
||||
// Register as default consumer for input
|
||||
InputManager.Instance?.SetDefaultConsumer(this);
|
||||
|
||||
_isInitialized = true;
|
||||
Debug.Log("[PlayerController] Initialized");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events to prevent memory leaks
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized -= Initialize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user