LoginSignup
5
5

More than 3 years have passed since last update.

Unityでオブジェクトを透明にしたいとき

Last updated at Posted at 2019-05-08

[結論]
MaterialのRendering ModeをOpaque以外にする

[経緯]
プログラムでオブジェクトの色を操作したい場合、
Render renderer=GetComponent();
Color c=renderer.material.color;

という形でcにオブジェクトのColorインスタンスを取り出すことができました。
ここで色のプロパティを操作することができます。
ということで透明度を変更するアルファ値を操作しようと思い

c.a+=0.1f;
c.a-=0.1f;

とコードを打ちましたが透明にならなかったので共有です。

[解説]
Unityのリファレンスを見ると
Unityリファレンス 「Albedo カラーと Transparency(透明度)」
https://docs.unity3d.com/ja/current/Manual/StandardShaderMaterialParameterAlbedoColor.html

opaque.PNG
「Opaque でないに設定されている場合は効果があります。」
と書かれていました。
Unity上ではこの部分に当たります。
material.PNG

OpaqueとはUnityのレンダリングモードの一つで、マテリアルを生成した時のデフォルト設定となっており
「透明な部分のない、一般的な固形のオブジェクトに適しています。」
と書かれています。
なので、この部分の設定を変えればよいです。
UnityリファレンスURL「Rendering Mode」
https://docs.unity3d.com/ja/current/Manual/StandardShaderMaterialParameterRenderingMode.html

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5