I am constrained in a current project demo (need to create for Monday) in that I cannot make use of any tweening libraries like DoTween or LeanTween.
I simply need to fade a canvas group object which I assume is possible using lerp.
Can anyone help?
Fading, simple and easy:
Don't use Mathf.Lerp(). Use Mathf.MoveTowards().
And definitely DO NOT USE COROUTINES (see my post above).
make some member variables:
private float desiredAlpha;
private float currentAlpha;
The work:
void Update()
{
currentAlpha = Mathf.MoveTowards( currentAlpha, desiredAlpha, 2.0f * Time.deltaTime);
}
Now, wherever you need to set fadedness of any object, use currentAlpha.
colorProperty.a = currentAlpha;
When you want to change fadedness, only set desiredAlpha equal to 0 or 1…
Smoothing movement between discrete values:
The problem is the choice of integer values for lanes. They can only either be lane 0, 1 or 2. They can’t be in between round numbers. It needs to be a floating point value so that it can be between lanes.
This type of question comes up so universally I have finally just made a sample package to demonstrate the basic concept. Read my first post above and see if you can correlate each part of the code to the steps indicated.
Code located here: SmoothMovement.cs · GitHub
6430100–719246–SmoothMo…
The code: Smooth movement - Pastebin.com