Hyluss

[Unity] RollDice, Action <T> callback

Sep 8th, 2017
296
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3.     void RollDice(RollDiceCmd rollDice)
  4.     {
  5.         int result = UnityEngine.Random.Range(1, 4);
  6.         float length = animatorController.animationClips[result - 1].length;
  7.         StartCoroutine(WaitToEndAnimation(result, length, (outcame) =>
  8.                 {
  9.                     rollDice.Result = outcame;
  10.                     Mediator.Instance.Publish<RollDiceCmd>(rollDice);
  11.                     Debug.Log("Your result " + rollDice.Result);
  12.                     StopAllCoroutines();
  13.                     animator.SetInteger("result", 0);
  14.                 }));        
  15.     }
  16.  
  17.     IEnumerator WaitToEndAnimation(int result , float length,Action<int> callback)
  18.     {
  19.         animator.SetInteger("result", result);
  20.         yield return new WaitForSeconds(length + 1);
  21.         callback(result);
  22.         yield return null;
  23.     }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment