smoothstepin tween in csharp

Here's an example of using smoothstepin tween in C#:

main.cs
using UnityEngine;

public class SmoothstepinTween : MonoBehaviour
{
    public Transform targetTransform;
    public float moveTime = 1f;
    public Vector3 startOffset = new Vector3(0, 0, 0);
    public Vector3 endOffset = new Vector3(5, 0, 0);

    private float elapsedTime = 0f;

    void Update()
    {
        elapsedTime += Time.deltaTime;

        float t = elapsedTime / moveTime;
        t = Mathf.Clamp01(t);

        Vector3 newPosition = Vector3.Lerp(startOffset, endOffset, Mathf.SmoothStep(0f, 1f, t));
        targetTransform.position = newPosition;
    }
}
575 chars
23 lines

In the above code, we're using Mathf.SmoothStep to calculate the smoothed value of t. t is then used to calculate the new position of the targetTransform, which is then updated in the Update() method. You can adjust the moveTime, startOffset, and endOffset values to control the speed and distance of the tween.

gistlibby LogSnag