How to make game object transparent in unity

Akari picture Akari · Oct 21, 2013 · Viewed 55.4k times · Source

In my game I want to make the player object transparent for 2 seconds by scripting at run time if the player collided with a specific object during the game ... is it possible ?

Answer

user2085599 picture user2085599 · Oct 21, 2013

Check for collision. When the collision that you want is triggered then you can change the transparency.

GameObject g;

// 50% Transparency.
g.renderer.material.color.a = 0.5f; // a is the alpha value.

 // 100% Transparency.
g.renderer.material.color.a = 1.0f;

You can do just this to make your program wait time: http://docs.unity3d.com/Documentation/Manual/Coroutines.html

You will notice the example is exactly your question.