示例#1
0
    private IEnumerator Crumble()
    {
        float timeStep = timeToCrumble / crumbleSteps;

        audioSource.clip = crumbleLiteClip;
        for (int i = 1; i <= crumbleSteps; i++)
        {
            shaker.Shake(10, 0.15f, 0.01f, true, Vector2.zero, false);
            mat.SetColor("_Color", Color.Lerp(startColor, endColor, i / (float)crumbleSteps));
            audioSource.Play();
            yield return(new WaitForSeconds(timeStep));
        }

        audioSource.clip = crumbleClip;
        audioSource.Play();
        coll.enabled = false;
        animator.SetBool("Crumbled", true);
        yield return(new WaitForSeconds(timeToRespawn));

        audioSource.clip = crumbleLiteClip;
        audioSource.Play();
        animator.SetBool("Crumbled", false);
        shaker.Shake(10, 0.15f, 0.01f, true, Vector2.zero, false);
        mat.SetColor("_Color", originalColor);
        coll.enabled = true;
        crumbling    = null;
    }
示例#2
0
    private void Update()
    {
        currentTime += Time.deltaTime;

        if (currentTime >= toggleTime - 0.15f)
        {
            //This first shake is a hack and can be better but oh no look at the time.
            shaker.Shake(10, 0.15f, 0.01f, true, Vector2.zero, false);
            if (currentTime >= toggleTime)
            {
                // Don't reset to 0, subtract toggleTime instead. Otherwise we'll eventually drift in timing.
                currentTime -= toggleTime;
                isSolid      = !isSolid;
                rend.enabled = isSolid;
                coll.enabled = isSolid;
                audioSource.Play();
                shaker.Shake(10, 0.15f, 0.01f, true, Vector2.zero, false);
            }
        }
    }