您好,登錄后才能下訂單哦!
小編給大家分享一下Unity如何實現單機游戲每日簽到系統,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
Unity實現每日簽到系統的具體代碼,具體內容如下
代碼:
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class HallManager : UnitySingleton<HallManager> { public Text textSingInCoinDes, textSingInCoin; public Button btnSignInNormal, btnSignInAd; //------------------------------------------ 簽到模塊 ------------------------------------------ /// <summary> /// 設置簽到數據 /// </summary> public void SetSignInPanelData() { if (string.IsNullOrEmpty(PlayerPrefs.GetString("SignInDay7"))) { for (int i = 0; i < 7; i++) { PlayerPrefs.SetString("SignInDay" + (i + 1), DateTime.Today.AddDays(i).ToShortDateString()); } } for (int i = 0; i < 7; i++) { if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1)))) { textSingInCoinDes.text = "今天領取"; textSingInCoin.text = signInCoin[i].ToString(); btnSignInNormal.gameObject.SetActive(true); btnSignInAd.gameObject.SetActive(true); signFinish.gameObject.SetActive(false); } else if ("已簽到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))) && i != 6) { textSingInCoinDes.text = "明天領取"; textSingInCoin.text = signInCoin[i + 1].ToString(); btnSignInNormal.gameObject.SetActive(false); btnSignInAd.gameObject.SetActive(false); signFinish.gameObject.SetActive(true); } } for (int i = 0; i < 7; i++) { if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))) || "已簽到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1)))) { if ("已簽到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1)))) { signInPanel.transform.Find("Items").GetChild(i).Find("YiQianDao").gameObject.SetActive(true); } else { signInPanel.transform.Find("Items").GetChild(i).Find("YiQianDao").gameObject.SetActive(false); } } } } /// <summary> /// 點擊普通簽到 /// </summary> void ClickBtnSignInNormal() { for (int i = 0; i < 7; i++) { if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1)))) { CoinManager.Instance.AddCoin(signInCoin[i]); PlayerPrefs.SetString("SignInDay" + (i + 1), "已簽到"); ShowRewardPanel(signInCoin[i]); } } SetUserInfo(); SetSignInPanelData(); //全屏廣告 MobileController.Instance.CallFullScreenAd(FullScreenAdRewardType.None); } /// <summary> /// 點擊視頻雙倍獎勵簽到 /// </summary> void ClickSignInAd() { MobileController.Instance.CallVedioRewardAd("signIn"); } /// <summary> /// 回調 - 視頻雙倍獎勵簽到 /// </summary> public void CallBackSignInReward() { for (int i = 0; i < 7; i++) { if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1)))) { CoinManager.Instance.AddCoin(signInCoin[i] * 2); PlayerPrefs.SetString("SignInDay" + (i + 1), "已簽到"); ShowRewardPanel(signInCoin[i] * 2); } } SetUserInfo(); SetSignInPanelData(); } }
以上是“Unity如何實現單機游戲每日簽到系統”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。