Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- void RollDice(RollDiceCmd rollDice)
- {
- int result = UnityEngine.Random.Range(1, 4);
- float length = animatorController.animationClips[result - 1].length;
- StartCoroutine(WaitToEndAnimation(result, length, (outcame) =>
- {
- rollDice.Result = outcame;
- Mediator.Instance.Publish<RollDiceCmd>(rollDice);
- Debug.Log("Your result " + rollDice.Result);
- StopAllCoroutines();
- animator.SetInteger("result", 0);
- }));
- }
- IEnumerator WaitToEndAnimation(int result , float length,Action<int> callback)
- {
- animator.SetInteger("result", result);
- yield return new WaitForSeconds(length + 1);
- callback(result);
- yield return null;
- }
Advertisement