Ejemplo n.º 1
0
    public void SetUnharvested(bool instant)
    {
        //instant occurs on a level reset
        if (instant)
        {
            if (WasHarvested && !canBeHarvested)
            {
                spriteRenderer.material = new Material(Resources.Load("Materials/Graphic/Active Letter") as Material);
                foreach (MeshRenderer mr in GetComponentsInChildren <MeshRenderer>())
                {
                    mr.material.color = spriteRenderer.material.GetColor("_EffectColor");
                }

                canBeHarvested = true;
                WasHarvested   = false;
                PlayerPhysics pp = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPhysics> ();
                if (pp.collisionLetter == this)
                {
                    pp.CheckForCollisions();
                }

                GameManager.increment_letters_active();
            }
        }
        else
        {
            if (!canBeHarvested)
            {
                StartCoroutine("TransitionToUnharvested");
            }
        }
    }
Ejemplo n.º 2
0
    IEnumerator TransitionToUnharvested()
    {
        float startTime = Time.time;

        //comparison material (the end material)
        Material compMaterial = new Material(Resources.Load("Materials/Graphic/Active Letter") as Material);

        Color startColor = spriteRenderer.material.GetColor("_EffectColor");
        Color endColor   = compMaterial.GetColor("_EffectColor");

        //Will need to change colors for the walkable platforms as well
        List <Material> walkable_mats = new List <Material> ();

        foreach (Transform child in this.transform)
        {
            if (child.tag == "Walkable")
            {
                walkable_mats.Add(child.GetComponent <MeshRenderer> ().material);
            }
        }

        while (Time.time - startTime <= 1f)
        {
            float timeElapsed = Time.time - startTime;
            Color newColor    = Color.Lerp(startColor, endColor, timeElapsed);

            spriteRenderer.material.SetColor("_EffectColor", newColor);

            //if letter is disappearing, walkable surfaces need to change with it
            newColor.a *= spriteRenderer.material.GetColor("_ColorMultiplier").a;
            foreach (Material mat in walkable_mats)
            {
                mat.color = newColor;
            }

            yield return(new WaitForEndOfFrame());
        }

        if (!HasDisappeared)
        {
            canBeHarvested = true;
            WasHarvested   = false;

            PlayerPhysics pp = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPhysics> ();
            if (pp.collisionLetter == this)
            {
                pp.CheckForCollisions();
            }

            GameManager.increment_letters_active();
        }
    }