Ludo-3D/Assets/Scripts/Input/DiceRollHandler.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2026-01-21 20:27:45 +05:30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiceRollHandler : MonoBehaviour
2026-01-21 20:27:45 +05:30
{
[SerializeField] private DiceView diceView;
[SerializeField] private int diceTestValue = 0;
2026-01-21 20:27:45 +05:30
private InputManager inputManager;
private void OnMouseDown()
{
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
if (!inputManager.GameplayManager.CanRollDice) return;
RollDiceOnClick();
2026-01-21 20:27:45 +05:30
}
private void Update()
{
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
if (!inputManager.GameplayManager.CanRollDice) return;
if (Input.GetKeyDown(KeyCode.Space))
RollDiceOnClick();
}
private void RollDiceOnClick()
2026-01-21 20:27:45 +05:30
{
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
soundManager?.PlayGameSoundClip(SoundType.Dice);
int currentRolledVal = // Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1);
diceTestValue != 0 ? diceTestValue : Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1);
2026-01-21 20:27:45 +05:30
inputManager.SetDiceRollValue(currentRolledVal);
}
public void HandleDiceView()
{
diceView.Roll();
}
2026-01-21 20:27:45 +05:30
}