Advertisement
uurha

Untitled

Jul 22nd, 2022 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. public async void ActivateRage()
  2. {
  3.     _isRage = true;
  4.     _bonusChanger.SetBonus(data.GetRageBonus(),bonusInstantiated);
  5.     await Task.Delay(5*1000);
  6.     _bonusChanger.SetBonus(null,bonusInstantiated);
  7.     _isRage = false;
  8. }
  9.  
  10. //If return type Task you can await this method in place where you call it
  11. public async Task ActivateRageTask()
  12. {
  13.     _isRage = true;
  14.     _bonusChanger.SetBonus(data.GetRageBonus(),bonusInstantiated);
  15.     await Task.Delay(5*1000);
  16.     _bonusChanger.SetBonus(null,bonusInstantiated);
  17.     _isRage = false;
  18. }
  19.  
  20. private async void ExampleMethod()
  21. {
  22.     ActivateRage();
  23.     Debug.Log("done 1"); //this line will be called without delay
  24.     await ActivateRageTask();
  25.     Debug.Log("done 2"); //this line will be called only after ActivateRageTask finished (after delay 5s).
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement