- Home /
Lerping a color.a upon Player Death?
Hi guys,
I'm an artist who is using Unity and familiarizing myself with C#. I'm pretty new to scripting. Here's a new problem I'm running into:
I have a spaceship game, and it's going pretty well. I'm trying to add an effect where upon death, a plane's material will interpolate between zero alpha (transparent) and complete alpha (black). As you probably guessed, this is to achieve the effect of the screen fading to black upon death.
Every time I try to access the color.a I get the error "Cannot Modify a Value Type Return Value" and after looking up solutions to that, I still can't get the screen to fade in.
Here's my code (It currently produces errors):
void Update ()
{
shipCollisionHealth shipCollisionHealthComponent = Body.GetComponent<shipCollisionHealth>();
if(shipCollisionHealthComponent.Health < 0.1f)
{
deathTimer += Time.deltaTime;
restartTimer += Time.deltaTime;
if(deathTimer >= 0.2f)
{
ShipExplosion.transform.localPosition = shipsPosition.localPosition;
ShipExplosion.SetActive (true);
ShipExplosionMesh.transform.localPosition = shipsPosition.localPosition;
ShipExplosionMesh.SetActive (true);
StarParticles.SetActive (false);
Ship.SetActive(false);
HUDCamera.SetActive (false);
HUDDarkenPlaneMat.SetColor ("DarkScreen", Mathf.Lerp (HUDDarkenPlane.renderer.material.color.a,1.0f,0.2f));
}
if(restartTimer >= 12.0f)
{
doOnce = true;
if(doOnce)
{
Application.LoadLevel (Application.loadedLevel);
doOnce = false;
}
}
}
}
}
Any help is appreciated! You guys have been super helpful!
Your answer
Follow this Question
Related Questions
Lerp Color doesn't work 2 Answers
How do I loop a Color32.Lerp? 3 Answers
How to make two colors lerp independently in this code? 1 Answer