-
-
Save isaveu/3ffe67f8b534d9f2d02e83cd7bbc2d9f to your computer and use it in GitHub Desktop.
Unity:自身のゲームオブジェクトに関連付けられた全てのマテリアルのアルファ値を0に近付けていって全てが透明になったらゲームオブジェクトを破棄する(マテリアルのShaderはTransparentに設定しておく)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlphaGameObject : MonoBehaviour | |
{ | |
private Color alpha = new Color(0, 0, 0, 0.01f); | |
private List<Material> materials = new List<Material>(); | |
private void Start() | |
{ | |
//マテリアルの取得 | |
foreach(Transform child in transform) | |
{ | |
if(child != null && child.renderer != null && child.renderer.material != null) | |
foreach(Material mat in child.renderer.materials) | |
materials.Add(mat); | |
} | |
} | |
private void Update() | |
{ | |
if(materials.Any(m => m.color.a > 0)) | |
materials.ForEach(m => m.color -= alpha); | |
else | |
Destroy(this.gameObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment