Standard shader transparency, works but not on it's own, why?

I am just learning to change color. This script works fine normally but when I change the standard shader from opaque to transparent it doesn’t work right away. When I press play the floor in completely transparent. I can’t toggle the color. It does start working if I hit the down arrow in the shader to show the full inspector window.

So opaque, all is fine. Transparent, it doesn’t work without opening shader. Any way to fix this and why this happens?

using UnityEngine;

public class Renderer_ChangeColor : MonoBehaviour
{
    private bool toggle = false;
    private GameObject floor;
    private Renderer rend;
    public Color32 shaderDefaultColor;

    private void Start()
    {
        floor = GameObject.Find("Floor");
        rend = floor.GetComponent<Renderer>();
        rend.material.shader = Shader.Find("Standard");
        shaderDefaultColor = rend.material.color;
    }
    
    private void Update()
    {
        ColorUsingShader();
    }

    void ColorUsingShader()
    {
        if (Input.GetKeyDown("t") && !toggle)
        {
            rend.material.SetColor("_Color", new Color32(100, 0, 0, 100));
            toggle = true;
        }
        else if (Input.GetKeyDown("t") && toggle)
        {
            rend.material.SetColor("_Color", (shaderDefaultColor));
            toggle = false;
        }
    }
}

It works for you WITH shader set to transparent? Mine doesn’t until I click the arrow by the shader. When I use your edited script script I get not normalized value errors. Without color32 the colors come back as weird decimals vs being 1-255. It also means (100, 0, 0, 100)); is (255, 0, 0, 255)). In other words the edits you made are not showing the colors correctly in my script.

I just noticed you have 1, 0, 0, 100 and When I had (100, 0, 0, 100). Above still applies. Your not getting the correct color by removing color32.

Which is why I m curious if you really got to work with transparency at all because alpha (the fourth number ends up being 255 after hitting play which is not transparent. Put a cube half way above the ground. Hit play. Is the bottom half transparent for you because that is step 1. While playing also check the color to make sure it’s correct color because I don’t see how you are with those changes.

I was looking for help, not giving it, lol It’s all good. :slight_smile: