Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development

Chris Kopcow
Chris Kopcow
2,852 Points

Changing render mode in Unity during runtime

Hi! I'm in the process of making my first game, and I'm running into an issue I can't solve.

The scene I'm working on is a 3D room with a top-down perspective, using a 2D sprite as the player. Since the front wall of the room will obscure the player when you walk to the bottom of the screen, I want to make the wall change to the Fade render mode when you walk toward it to make the player visible, while making it clear the wall is still there.

Looking through Unity forums and documentation, it seems you enable the keyword "_ALPHABLEND_ON" to use the Fade render mode, but when I did this, it didn't work. (Even worse, other variations of my code caused my sprite to clip through the wall and fall into the void below.)

Here is my current code:

public class FadeOut : MonoBehaviour {

    private Transform player;
    private Material standardShader;

    // Use this for initialization
    void Start ()
        standardShader = GetComponent<Renderer>().material;

    // Update is called once per frame
    void Update ()
        if (player.position.z >= 7.78f)

I've looked everywhere online, and I've tried a few of the solutions other people have offered, but nothing seems to work. This seems like it should be easier to execute than it is, considering how easy it is to modify everything else in a material.

Can anyone help?