*Materialの「Rendering Mode」を「Fade」に設定する。
(基本)徐々に透過度を変化させる
using UnityEngine;
using System.Collections;
public class FadeInOut : MonoBehaviour {
// Color(r,g,b,a)
Color alpha = new Color(0, 0, 0, 0.04f);
private MeshRenderer mesh;
void Start () {
// 対象となるオブジェクトのMeshRenderコンポーネントを取得する。
mesh = GetComponent<MeshRenderer>();
}
void Update () {
if(mesh.material.color.a >= 0){
// 透過度(a=alpha)の値を小さくしていく
mesh.material.color -= alpha;
}
}
}
(応用)ボタンの入力の有無に応じて、透過度を変化させる
using UnityEngine;
using System.Collections;
public class FadeInOut : MonoBehaviour {
// Color(r,g,b,a)
Color alpha = new Color(0, 0, 0, 0.04f);
private MeshRenderer mesh;
void Start () {
// 対象となるオブジェクトのMeshRenderコンポーネントを取得する。
mesh = GetComponent<MeshRenderer>();
}
void Update () {
if(Input.GetButton("Jump")){
mesh.material.color += alpha;
} else {
mesh.material.color -= alpha;
}
}
}
