您的位置:首页 > 移动开发 > Unity3D

unity模型缩放趋势控制。

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

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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: