当前位置:   article > 正文

Unity简单的ease模拟_unity 移动ease

unity 移动ease

Unity简单的ease模拟

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//简单的ease曲线模拟
//f(s+(e-s)*(E/T))
public class EaseTest : MonoBehaviour
{
    public Vector3 endpos;
    [Range(0, 10)]
    public float totaltime;
    private Vector3 startpos;
    private float elapsedtime;
    // Start is called before the first frame update
    void Start()
    {
        startpos = transform.position;
    }
    //0 ~ 1
    private float coefficient;
    // Update is called once per frame
    void Update()
    {
        elapsedtime += Time.deltaTime;
        if (this.transform.position != endpos)
        {
            coefficient = elapsedtime / totaltime;
            if (coefficient >= 1)
                coefficient = 1;
            print(coefficient);
            this.transform.position = startpos + (endpos - startpos) * coefficient;
        }
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/125936
推荐阅读
相关标签
  

闽ICP备14008679号