Пример #1
0
    //float t, float amplitude, float frequency
    public void ShakeCamera(VisualEffectSize size)
    {
        if (size < currentShake)
        {
            return;
        }
        StopAllCoroutines();
        currentShake = size;
        switch (size)
        {
        case VisualEffectSize.SMALL:
            StartCoroutine(Shake(tSmall, aSmall, fSmall));
            break;

        case VisualEffectSize.BIG:
            StartCoroutine(Shake(tBig, aBig, fBig));
            break;
        }
    }
Пример #2
0
    private IEnumerator Shake(float _t, float _amplitude, float _frequency)
    {
        Transform trans                   = Camera.main.transform;
        Vector3   deltaPosition           = Vector3.zero;
        Vector3   movement                = Vector3.zero;
        float     timeFromDirectionChange = 0;
        float     timeFromStart           = 0;

        while (true)
        {
            if (timeFromDirectionChange >= _frequency)
            {
                movement = new Vector3(Random.Range(-_amplitude, _amplitude), Random.Range(-_amplitude, _amplitude), Random.Range(-_amplitude, _amplitude));
            }
            yield return(new WaitForEndOfFrame());

            trans.position          += movement * Time.deltaTime;
            deltaPosition           += movement * Time.deltaTime;
            timeFromDirectionChange += Time.deltaTime;
            timeFromStart           += Time.deltaTime;
            if (timeFromStart >= _t)
            {
                break;
            }
        }
        while (true)
        {
            yield return(new WaitForEndOfFrame());

            trans.position -= deltaPosition * Time.deltaTime * comeBackSpeed;
            deltaPosition  -= deltaPosition * Time.deltaTime * comeBackSpeed;
            if ((Vector3.SqrMagnitude(deltaPosition) <= 0.2f * 0.2f) || timeFromStart > _t * 1.5f)
            {
                break;
            }
        }
        currentShake = VisualEffectSize.NULL;
    }
Пример #3
0
    public static GameObject LoadVisualEffect(VisualEffectShape shape, VisualEffectSize size, string name = "")
    {
        GameObject result = Resources.Load("Effect Zones/" + shape + "/" + size + name) as GameObject;

        return(result);
    }
Пример #4
0
    public static GameObject LoadVisualEffect(VisualEffectShape shape, VisualEffectSize size)
    {
        GameObject result = Resources.Load("Visual Effects/" + shape + "/" + size) as GameObject;

        return(result);
    }