Last active
May 16, 2016 00:40
-
-
Save EsProgram/0c1b47918772c2c12ba8 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