Пример #1
0
    void Update()
    {
        timeSinceRun += Time.deltaTime;
        float amountMoved = collectionSpeed.Evaluate((timeSinceRun) * collectSpeedMod);

        switch (animationType)
        {
        case AnimationOccuring.collecting:
            gem.position  = Vector3.Lerp(origPos, targetPos, amountMoved);
            gem.position += perpVector * (1 - Mathf.Pow((2f * amountMoved - 1), 2f));

            gem.localScale = Vector3.Lerp(origScale,
                                          new Vector3(targetCollectSize, targetCollectSize, targetCollectSize),
                                          amountMoved);

            if (amountMoved.Equals(1f))
            {
                screenShake.shakeTime = 0.7f;
                GetComponent <ParticleSystem>().Play();
                animationType = AnimationOccuring.none;

                //Make opaque again
                matColor   = GetComponentInChildren <MeshRenderer>().material.color;
                matColor.a = 1f;
                GetComponentInChildren <MeshRenderer>().material.color = matColor;
            }
            break;

        case AnimationOccuring.destroying:

            //Move gem
            gem.position   = Vector3.Lerp(origPos, targetPos, amountMoved);
            gem.position  += Random.insideUnitSphere * amountMoved;
            gem.localScale = Vector3.Lerp(origScale,
                                          new Vector3(targetDestroySize, targetDestroySize, targetDestroySize),
                                          amountMoved);

            //Update color
            matColor = GetComponentInChildren <MeshRenderer>().material.color;
            matColor = Color.Lerp(matColor, Color.black, amountMoved * 1.5f);
            GetComponentInChildren <MeshRenderer>().material.color = matColor;

            //Slow down time
            Time.timeScale = (1 - amountMoved);
            if (amountMoved.Equals(1f))
            {
                animationType = AnimationOccuring.none;
            }

            break;

        case AnimationOccuring.none:

            break;
        }
    }
Пример #2
0
    public void DestroyGem()
    {
        animationType = AnimationOccuring.destroying;

        //Get the eventual position that this gem will settle into
        targetPos =
            transform.position +
            Camera.main.transform.forward * -3f;

        StartAnim();
    }
Пример #3
0
    public void CollectGem(int collectedGems)
    {
        animationType = AnimationOccuring.collecting;

        //Make the gem transparent
        matColor   = GetComponentInChildren <MeshRenderer>().material.color;
        matColor.a = 0.3f;
        GetComponentInChildren <MeshRenderer>().material.color = matColor;

        //Get the eventual position that this gem will settle into
        targetPos =
            new Vector3(16.2f, 5f, -21.7f) +
            Camera.main.transform.right * 1.5f * collectedGems +
            Camera.main.transform.up * 0.5f;

        //Calculate the two vectors to travel - linear and polynomial curve direction
        targetPosRelative = targetPos - gem.position;
        perpVector        = Vector3.Normalize(Vector3.Cross(targetPosRelative, Vector3.up));
        perpVector       *= (targetPosRelative.magnitude) / 5f;

        StartAnim();
    }