###前提・実現したいこと
Unityを使用しカレンダーの作成を行っています。
当方初心者のためこちらのサイト"http://tiwaluna.hatenablog.com/entry/2017/02/18/000515"を参考に進めております。
こちらのサイトに載っているソースコードをそのままC#でプログラミングしている途中です。
サイトの通りに進めているのですが以下のようなエラーが出てしまいお手上げ状態です。
VisualStudioで正常にビルドはできます。
###発生している問題・エラーメッセージ
エラーメッセージ
IndexOutOfRangeException: Array index is out of range.
(wrapper stelemref) object:stelemref (object,intptr,object)
CalendarManager.InitCalendarComponent () (at Assets/CalendarManager.cs:62)
CalendarManager.Start () (at Assets/CalendarManager.cs:30)
###該当のソースコード
ここにご自身が実行したソースコードを書いてください
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
public class CalendarManager : MonoBehaviour
{
///<summaryボタンの親オブジェクト</summary> public GameObject calenderParent; /// <summary>来月へ</summary> public Button nextButton; /// <summary>先月へ</summary> public Button prevButton; /// <summary>カレンダーの日時</summary> public DateTime current; /// <summary>Buttonオブジェクト</summary> GameObject[] objDays = new GameObject[42]; /// <summary>カレンダーの日付マス</summary> CalendarButton[] Days = new CalendarButton[42]; // Use this for initialization void Start() { current = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); InitCalendarComponent(); SetCalendar(); if (nextButton != null) { //押されたら起動 nextButton.onClick.AsObservable() .Subscribe(_ => { //一つ月を進める current = current.AddMonths(1); SetCalendar(); }); } if (prevButton != null) { prevButton.onClick.AsObservable() .Subscribe(_ => { current = current.AddMonths(-1); SetCalendar(); }); } } /// <summary>コンポーネントの取得、設定</summary> void InitCalendarComponent() { //行 for (int i = 0; i < calenderParent.transform.childCount; i++) { //子オブジェクトを保存 objDays[i] = calenderParent.transform.GetChild(i).gameObject; //コンポーネントを設定、取得 Days[i] = objDays[i].AddComponent<CalendarButton>(); Days[i].index = i + 1; } } /// <summary>カレンダーに日付をセット</summary> void SetCalendar() { int day = 1; //今月の1日目 var first = new DateTime(current.Year, current.Month, day); //来月 var nextMonth = current.AddMonths(1); int nextMonthDay = 1; //先月 var prevMonth = current.AddMonths(-1); //先月の場合は後ろから数える。 int prevMonthDay = DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month) - (int)first.DayOfWeek + 1; foreach (var cDay in Days) { //今月の1日より前のマスには先月の日にちを入れる。 if (cDay.index <= (int)first.DayOfWeek) { cDay.dateValue = new DateTime(prevMonth.Year, prevMonth.Month, prevMonthDay); prevMonthDay++; } //今月の最終日より後ろのマスには来月の日にちを入れる。 else if (day > DateTime.DaysInMonth(current.Year, current.Month)) { cDay.dateValue = new DateTime(nextMonth.Year, nextMonth.Month, nextMonthDay); nextMonthDay++; } //今月の日にちをマスに入れる。 else { cDay.dateValue = new DateTime(current.Year, current.Month, day); day++; } } }
}
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
Windows8.1
Unity 5.6.1
VisualStudio2017
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。