Fading not working out as intended
I wanted an object to fade out, but instead of fading, it kind of deep fries itself, like this:
As you can see, it actually does allow light to pass through and see objects behind, but it doesn't necessarily fade. At first, I thought it was a problem where one of the scripts in the star makes the star go rainbowy colored, and it intefered with the fade script in the main script, but when I merged them together, it still has a problem. When debugging, I turned off the color changing script, and made it so then the Alpha of the color is set to 50, but it still turns itself white. Any ideas what went wrong?
Code:
// Update is called once per frame
void Update()
{
// When the star reaches it's predefined y value, it will explode
if (transform.position.y < 5) {
Explode();
hasExploded = true;
StartCoroutine(DestroySelf());
}
// Runs the following code if it has exploded
if (hasExploded) {
// Gets the current color to keep the color while it's fading.
Color objColor = GetComponent<Renderer>().material.color;
// Set the fade amount to increase as time goes on
float fadeAmount = objColor.a + (fadeSpeed * Time.deltaTime);
// Sets the alpha argument to the fade amount
material.color = new Color(material.color.r, material.color.g, material.color.b, fadeAmount);
// Scale the star up by the scale speed
transform.localScale += new Vector3(scaleSpeed, scaleSpeed, scaleSpeed) * Time.deltaTime;
}
// Gets the current color and converts it to HSV
Color.RGBToHSV(material.color, out hue, out saturation, out brightness);
// Sets the saturation and brightness
saturation = 0.5f;
brightness = 1.0f;
// If it hasn't exploded, make it go rainbowy
if (delay <= 0.0f && !hasExploded) {
hue += rainbowSpeed;
material.color = Color.HSVToRGB(hue, saturation, brightness);
delay = resetTime;
}
delay -= Time.deltaTime;
// If the hue is at it's maximum, reset it
if (hue >= 1) {
hue = 0.0f;
}
}
Your answer
Follow this Question
Related Questions
How do i remove colored circles on materials? 0 Answers
Material darker in inspector then scene? 0 Answers
Every object I drag into the scene turns yellow 0 Answers
All my models are white 2 Answers