Search code examples
c#unity-game-engineunityscript

How to make game object transparent in unity


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 ?


Solution

  • 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.