LoginSignup
2
0

More than 1 year has passed since last update.

アドベントカレンダー作ってみた

Last updated at Posted at 2022-12-10

【完走目指す】初心者が25日で強くなる Advent Calendar 2022
11日目の記事です。なんかカレンダーがうまく紐づけられないので、この記事はすぐに消すかもしれません 
追記
書き直して、何とかできました。よかった

アドベントカレンダー 

クリスマスも近いので、アドベントカレンダーを作ります。 
作るのは普通の、クリスマスまで1日ずつ日付をめくっていくあのアドベントカレンダーです。

構想

ざっくりこんな感じに作りたいです。
1.日付を取得
2.その日付までの画像を別のプレゼントに入れ替える。
3.プレゼントの中身が見れてうれしい

制作開始 

まずは、画像を25日分用意します。
画像は自分で用意しました。フリー画像を持ってきてもいいでしょう。
プレゼント赤.png
いい感じに並べます。
スクリーンショット_20221211_015005.png
並びました

次に、プレゼントの中身を考えます。今回はクリスマスにちなんで「シュトーレン」にしました。
一応、画像は自分で作りました。
シュトーレンの代わり.png
今回使う、シュトーレンの代わりです。手抜きです。

書く

以下のものを書きました。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class AdvCal : MonoBehaviour
{
    public int Day;
    public int Month;
    public GameObject[] Hako;
    public GameObject Warn1;
    public GameObject Warn2;
    // Start is called before the first frame update
    void Start()
    {
        Warn1.SetActive(false);
        Warn2.SetActive(false);
        
    }

    // Update is called once per frame
    void Update()
    {
        Month = DateTime.Now.Month;
        Day = DateTime.Now.Day;
        if (Month == 12)
        {
            if (Day <= 25)
            {
                for (int B = 0; B < Day; B++)
                {
                    Hako[B].SetActive(false);

                }


            }
            else
            {
                Warn1.SetActive(true);

            }

        }
        else
        {
            Warn2.SetActive(true);
        }
    }
}

Warn1
warn1.png
とWarn2
warn2.png

の画像を用意しました。
Warn1は12月で、クリスマスが終わった12月26日とかに出ます。
Warn2は、12月じゃないときに出ます。

結果

スクリーンショット_20221211_021859.png
(シュトーレン見づらいけど)

一発で動いた!

  

まとめ

時間に余裕をもって記事を書こう。
ちなみに、ちゃんと保存できてなかったみたいで一回この記事は消えました。

11日目 終わり

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0