unity模型缩放趋势控制。

来源:互联网 发布:axure 8.0mac安装教程 编辑:程序博客网 时间:2024/05/18 01:22

最近一直碰到一个需求,就是游戏模型在生成的一瞬间要有缩放的动画,增加动感。所以特别写了个脚本给策划进行控制,源码如下:

using System.Collections;using System.Collections.Generic;using UnityEngine;public class ScaleChange : MonoBehaviour {    public AnimationCurve animationCurve;    public float scaleTime;    private  Vector3 modelScale;void Update ()     {        if(Input.GetMouseButtonDown(0))        {            StartCoroutine(ChangeScale());        }}    IEnumerator ChangeScale()    {        float currentTime = 0;        while(currentTime<scaleTime)        {            float animationScale = animationCurve.Evaluate(currentTime/scaleTime);            this.transform.localScale = new Vector3(modelScale.x * animationScale, modelScale.y * animationScale, modelScale.z*animationScale);            currentTime += Time.deltaTime;            yield return new WaitForEndOfFrame();        }        this.transform.localScale = modelScale;    }}


0 0