Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Created April 29, 2015 07:03
Show Gist options
  • Save grimmdev/f0427cd88e6288a8cf87 to your computer and use it in GitHub Desktop.
Save grimmdev/f0427cd88e6288a8cf87 to your computer and use it in GitHub Desktop.
Very simple C# unity static class to check if the user is capable of getting his reward bonus. Easily customizable.
// Sean Loper
// Hourly Bonus Mechanic 1.0
// Very simple to expand and static functions for easy calling
// also simple bool checks with custom hour input.
// You can easily add your own saving and loading function check before
// the calculations of thisTime and lastTime;
using System;
using UnityEngine;
using System.Collections;
public class HourlyBonus {
private static DateTime thisTime;
private static DateTime lastTime;
private static TimeSpan diffTime;
public static bool Reward(){
thisTime = DateTime.Now;
diffTime = thisTime - lastTime;
if(diffTime.TotalHours >= 1){
lastTime = thisTime;
return true;
}else{
return false;
}
}
public static bool Reward(int hour){
thisTime = DateTime.Now;
diffTime = thisTime - lastTime;
if(diffTime.TotalHours >= hour){
lastTime = thisTime;
return true;
}else{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment