UIのImageをフェードインさせてみる
タイトル画面とかでタイトルの画像をフェードインさせたい時もある。
ということで、簡易的なサンプルを作ってみました。
まず、uiでImageを配置します。

こんな感じ。

配置した画像にフェードイン用(New Script)のスクリプトをアタッチします。

スクリプトは以下のような感じです。※もっと良いやり方はあるかも(汗
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FadeIn : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Color color = gameObject.GetComponent().color;
color.a = 0.0f;
gameObject.GetComponent().color = color;
}
// Update is called once per frame
void Update()
{
Color color = gameObject.GetComponent().color;
if (color.a <= 1.0f)
{
color.a += 0.001f;
gameObject.GetComponent().color = color;
}
}
}
「color.a += 0.001f;」の部分の数値を変更すると早くフェードインしたり、遅くフェードインさせたりすることが出来ます。(・。・ノ



![[Unity]Terrainに生やした草をスクリプトから消す](https://kuroko-labo.com/wp/wp-content/uploads/2025/05/grass2.png)
![[Unity]PhotonのPUN2で任意のタイミングでメソッドを実行する](https://kuroko-labo.com/wp/wp-content/themes/kuroko3/images/noimage.png)
![[Unity]Gaia Pro 2023でフィールドを作ってみた](https://kuroko-labo.com/wp/wp-content/uploads/2025/01/image06.png)