Game Development Unity Animation Curve to vary worth over time Team FunTrove - October 22, 2022 0 [ad_1] Unity Animation Curve to vary worth over time – Game Development Stack Exchange Stack Exchange Network Stack Exchange community consists of 182 Q&A communities together with Stack Overflow, the most important, most trusted on-line group for builders to study, share their data, and construct their careers. Visit Stack Exchange Log in Sign up Game Development Stack Exchange is a query and reply web site for skilled and impartial sport builders. It solely takes a minute to enroll. Sign as much as be a part of this group Anybody can ask a query Anybody can reply The finest solutions are voted up and rise to the highest Asked 3 years, 5 months in the past Viewed 555 occasions $begingroup$ I’m attempting to discover ways to use AnimationCurve to vary a float worth over time. However i’m not actually certain learn how to do it Say i’ve the next class: public class SpiritAway : MonoBehaviour { public List<SkinnedMeshRenderer> MeshList; public List<Material> DissolveList; public float proportion = 0.0f; public bool IsDissolveing; public AnimationCurve Curve; personal void Start() { proportion = 0.0f; for (int i = 0; i < MeshList.Count; i++) { for (int j = 0; j < MeshList[i].supplies.Length; j++) { if (MeshList[i].supplies[j].shader.title == "Dissolve") { DissolveList.Add(MeshList[i].supplies[j]); } } } } // Update is named as soon as per body void Update() { if (IsDissolveing) { if (proportion < 1) { proportion += 0.01f; for (int i = 0; i < DissolveList.Count; i++) { DissolveList[i].SetFloat("_alphaClipDissolve", proportion); } } } } Now i want to incrase the share worth with the share of the animation curve to get a extra clean and managed transition of the worth. Could anybody clarify how that is potential? requested May 7, 2019 at 11:14 Marc RasmussenMarc Rasmussen 37111 gold badge55 silver badges1717 bronze badges $endgroup$ 1 $begingroup$ It appears to be like to me like you possibly can exchange this with: public float velocity = 1f/30f; public Renderer[] renderers; public AnimationCurve curve; MaterialPropertyBlock _block; struct MaterialSlot { public readonly Renderer renderer; public readonly int index; public MaterialSlot(Renderer renderer, int index) { this.renderer = renderer; this.index = index; } } personal IEnumerator Start() { // Define a cloth property block for modifying alpha // with out copying supplies (lighter on allocations/rubbish). var properties = new MaterialPropertyBlock(); // Cache an ID for our parameter, to keep away from a number of string lookups. int id = Shader.PropertyToIndex("_alphaClipDissolve"); float perecentage = 0f; // Read our alpha worth from this place on the curve // and apply it to our property block. properties.SetFloat(id, curve.Evaluate(proportion)); // Find all supplies that want this alpha adjusted, and cache them. var slots = new List<MaterialSlot>(); foreach(var renderer in renderers) { // Look on the renderer's supplies with out copying them. var supplies = renderer.sharedMaterials; for(int i = 0; i < supplies.Length; i++) { if(supplies[i].shader.title == "Dissolve") { // Initialize the alpha worth for this materials. renderer.SetPropertyBlock(properties, i); // Cache a reference to its slot so we are able to iterate it later. var slot = new MaterialSlot(renderer, i); slots.Add(slot); } } } // Keep updating the alpha on subsequent frames till we're finished. whereas(proportion < 1f) { // Wait a body, then resume. yield return null; // Advance the animation at a set price over time. proportion += Time.deltaTime * velocity; // Read our alpha worth from this place on the curve // and apply it to our property block. properties.SetFloat(id, curve.Evaluate(proportion)); // Apply this modified property block to each "Dissolve" materials slot. foreach(var slot in slots) { slot.renderer.SetPropertyBlock(properties, slot.index); } } // p.c >= 1f, we're finished! End this coroutine. } answered May 7, 2019 at 17:40 DMGregory♦DMGregory 119k2222 gold badges215215 silver badges320320 bronze badges $endgroup$ You should log in to reply this query. Not the reply you are on the lookout for? Browse different questions tagged . lang-cs Your privateness By clicking “Accept all cookies”, you agree Stack Exchange can retailer cookies in your system and disclose info in accordance with our Cookie Policy. Accept all cookies Customize settings [ad_2] LEAVE A REPLY Cancel reply Please enter your comment! Please enter your name here You have entered an incorrect email address! Please enter your email address here Save my name, email, and website in this browser for the next time I comment.