Material lerp on keyup
I'm trying to have the pink material fade to the black one and have the light fade out after lifting the key, but whenever I have tried to fix this it would either get stuck on one material, or have everything happen in one frame. This is the code before adding the material fade out, because all of my solutions have failed.
using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using UnityEngine; using UnityEngine.Rendering; public class Main : MonoBehaviour { public string key; public Material BlackMat; public Material PinkMat; Renderer rend; Light myLight; // Start is called before the first frame update void Start() { rend=GetComponent<Renderer>(); myLight = GetComponent<Light>(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(key)) { rend.material = PinkMat; myLight.intensity = 2; } else if (Input.GetKeyUp(key)) { rend.material = BlackMat; myLight.intensity = 0; } } }
Your answer
Follow this Question
Related Questions
Material lerp fade out on keyup 1 Answer
Instantiate screenshots from camera *Realtime* 0 Answers
Can you make the player do a 180° / u-turn when a button is pressed? 0 Answers
How to know whether material's emission is enabled or not by C# script? 0 Answers
Lightweight RP change texture scale 0 Answers