用Tween动画简单模拟果冻按钮效果

  网上有关于果冻效果的插件JellySprites,我呢,只想要一个点击一下按钮,按钮会像果冻一样动一下。没必要弄那么复杂。我就用tween动画写了一下。写出分享给大家。

using UnityEngine;
using System.Collections;

public class JellyButton : MonoBehaviour {

    Vector3 m_Scale;

    void Start() {
        m_Scale = transform.localScale;       
    }

    void OnClick()
    {
        StartCoroutine(JellyEffect());
    }

    IEnumerator JellyEffect() {
        TweenScale.Begin(gameObject, 0.05f, new Vector3(m_Scale.x * 1.1f, m_Scale.y * 0.8f, m_Scale.z));
        yield return new WaitForSeconds(0.05f);
        TweenScale.Begin(gameObject, 0.1f, new Vector3(m_Scale.x * 0.8f, m_Scale.y * 1.1f, m_Scale.z));
        yield return new WaitForSeconds(0.1f);
        TweenScale.Begin(gameObject, 0.1f, new Vector3(m_Scale.x * 1.07f, m_Scale.y * 0.85f, m_Scale.z));
        yield return new WaitForSeconds(0.1f);
        TweenScale.Begin(gameObject, 0.15f, new Vector3(m_Scale.x * 0.85f, m_Scale.y * 1.07f, m_Scale.z));
        yield return new WaitForSeconds(0.15f);
        TweenScale.Begin(gameObject, 0.2f, new Vector3(m_Scale.x * 1.05f, m_Scale.y * 0.9f, m_Scale.z));
        yield return new WaitForSeconds(0.2f);
        TweenScale.Begin(gameObject, 0.2f, new Vector3(m_Scale.x * 0.95f, m_Scale.y * 1.035f, m_Scale.z));
        yield return new WaitForSeconds(0.2f);
        TweenScale.Begin(gameObject, 0.25f, m_Scale);
    }
}


你可能感兴趣的:(unity)