Unity 实现按钮点击 某物体缓慢放大效果 比如打开商店

来源:互联网 发布:3d人体模型软件 编辑:程序博客网 时间:2024/06/16 06:54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ButtonOnclick : MonoBehaviour {
    public AnimationCurve curve;//放大的曲线
    public Button But;
    private float value = 0;
    // Update is called once per frame
    void Start () {
        But.onClick.AddListener (delegate {
            if(this.gameObject.activeSelf==true){
                StartCoroutine (buttonAnimation());
            }
        });
    }
    IEnumerator buttonAnimation(){
        value = 0;
        while (true) {
            this.transform.localScale=Vector3.one*curve.Evaluate (value+=Time.deltaTime*2);
            yield return null;
            if (value>=1) {
                break;
            }
        }
    }
}
原创粉丝点击