「Unity」フェード処理について
iTeenでフェード処理作成時、”Imageのカラーが徐々に変化しない”って悩んでたけど、
しょうもない勘違いしていたのでメモ。
結論から言うと、
「0~1」で設定しなければならない値を
「0~255」にしていたっていうオチ。
...思い込みって怖い。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;//UI関連(Image) public class FadeAction : MonoBehaviour { private const float fadeTime = 1.0f; // Use this for initialization void Start () { FadeOutAction (); } // Update is called once per frame void Update () {} // フェードアウト処理 public void FadeOutAction(){ iTween.ValueTo (gameObject, iTween.Hash( "from", 1.0f, "to", 0.0f, "time", fadeTime, "onupdate", "SetAlphaValue" )); } // フェードイン処理 public void FadeInAction(){ iTween.ValueTo (gameObject, iTween.Hash( "from", 0.0f, "to", 1.0f, "time", fadeTime, "onupdate", "SetAlphaValue" )); } // アルファ値を変更する処理 void SetAlphaValue(float alpha){ gameObject.GetComponent<Image> ().color = new Color (0,0,0,alpha); //Debug.Log("alpha : " + alpha); } }