Ví dụ sử dụng InvokeRepeating để chạy tác vụ như sau:
public int count; //tạo 1 biến đếm
public void BtExitClicked() //hàm này được gọi khi ấn nút Exit
{
count= 0;
InvokeRepeating ("InvokeExit", 0.5f, 1f);
print("InvokeExit ***");
}
Viết hàm InvokeExit :
void InvokeExit()
{
count++;
if (count== 1)
{
GoogleAdmob.GetComponent<GoogleAdmob>().showInterstitial(); //hiện quảng cáo
}
if (count== 2)
{
CancelInvoke("InvokeExit"); //hủy
//sau đó thoát chương trình:
Application.Quit();
}
}
Không có nhận xét nào:
Đăng nhận xét