반응형
- 코드 작성
using UnityEngine;
using UnityEngine.UI;
public class AttendanceManager : MonoBehaviour
{
public Text[] dayTexts; // 출석 상태를 표시할 Text 개체 배열
public Button attendanceButton; // 현재 날짜의 출석을 기록할 버튼
private int currentDay; // 현재 날짜 (첫 번째 날은 0)
private bool[] attendanceRecord = new bool[7]; // 7일 동안의 출석 기록
private void Start()
{
LoadAttendanceData();
UpdateUI();
}
// PlayerPrefs에서 출석 데이터를 불러옵니다.
private void LoadAttendanceData()
{
for (int i = 0; i < 7; i++)
{
attendanceRecord[i] = PlayerPrefs.GetInt("Day" + i, 0) == 1;
}
}
// PlayerPrefs에 출석 데이터를 저장합니다.
private void SaveAttendanceData()
{
for (int i = 0; i < 7; i++)
{
PlayerPrefs.SetInt("Day" + i, attendanceRecord[i] ? 1 : 0);
}
PlayerPrefs.Save();
}
// 현재 날짜의 출석을 기록합니다.
public void MarkAttendance()
{
if (currentDay < 7 && !attendanceRecord[currentDay])
{
attendanceRecord[currentDay] = true;
SaveAttendanceData();
UpdateUI();
}
}
// 출석 상태를 반영하기 위해 UI를 업데이트합니다.
private void UpdateUI()
{
for (int i = 0; i < 7; i++)
{
if (i < currentDay)
{
dayTexts[i].text = "Day " + (i + 1) + " - 출석 완료";
}
else if (i == currentDay)
{
dayTexts[i].text = "Day " + (i + 1) + " - 오늘";
}
else
{
dayTexts[i].text = "Day " + (i + 1) + " - 미출석";
}
}
attendanceButton.interactable = currentDay < 7 && !attendanceRecord[currentDay];
}
}
반응형
'개발 > C#' 카테고리의 다른 글
C# DFS (깊이 우선 탐색) 알고리즘 예시 간단 구현 (0) | 2023.10.20 |
---|---|
C# BFS (너비 우선 탐색) 알고리즘 예시 간단 구현 (0) | 2023.10.20 |
C# 그리디 알고리즘 (Greedy 탐욕) 예시 간단 구현 (0) | 2023.10.20 |
C# 버블, 선택, 삽입, 퀵 정렬 예시 간단 구현 (0) | 2023.10.20 |
유니티 C# UI 이미지 FillAmount 서서히 감소시키기 간단 구현 (0) | 2023.09.14 |
유니티 C# Byte[] To String PlayerPrefs 저장 불러오기 간단 구현 (0) | 2023.08.30 |
유니티 C# 슬롯머신 간단 구현 Unity Slot machine (0) | 2023.08.17 |
유니티 C# 캐릭터 주변 원 운동 오브젝트 간단 구현 및 데미지 주기 (0) | 2023.08.17 |
댓글