- Home /
Editing alpha through a script and animation changes the colour not the transparency?
so i have a material, and a script that gets the alpha and applies the alpha to the material, script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class alphatracker : MonoBehaviour
{
public Material mat;
public float alpha;
// Update is called once per frame
void Update()
{
if (mat != null)
{
mat.color = new Color(mat.color.r, mat.color.b, mat.color.g, alpha);
}
}
}
ok and i have an animation that edits this 'alpha' value, from 1 to zero.
so, i'd expect this animation to edit the transparency but instead it just changes the purple to yellow alot. (sorry for the bad quality, the unity file size limit is so low, i had to compress it. and that VEED.IO watermark is me trimming the video using veed because even compressing it was not enough)
so what is the problem??
Answer by xxmariofer · Aug 23, 2021 at 06:37 AM
the color changes because is "rgb" not "rbg", every frame you are changing those values.
For the material to be transparent you need to click that material from the inspector, and change its render mode to transparent
wow, hitting two birds with one stone, you solved both of my problems. although for my unity it was surface type to transparent and not render mode but i got there.
Your answer
Follow this Question
Related Questions
3d Animated Jump Script 0 Answers
Animator transition help 0 Answers
Animation keeps repeating 2 Answers
Efficient way to instantiate a sprite that plays an animation then destroys itself? (3d space) 1 Answer
Sprite animation from 2D to 3D 2 Answers