IEnumerator StreamCubes()
    {
        if (m_animator == null)
        {
            m_animator = GetComponentInChildren <Animator>();
        }

        ClipPlanePoints clipPoints = ClipPlanePoints.Instance;
        Camera          camera     = clipPoints.Camera;

        //TODO: Don't hard-code this...
        while (clipPoints.CollidesBottom(transform.position, -.1f))
        {
            yield return(new WaitForSeconds(.1f));
        }

        m_animator.SetBool("isEnabled", true);

        //TODO: Don't hard-code this...
        while (!clipPoints.CollidesTop(transform.position, -3.3f))
        {
            yield return(new WaitForSeconds(.1f));
        }

        m_animator.SetBool("isEnabled", false);
    }
Exemple #2
0
    IEnumerator SpawnFlyingCubes(FlyingCube prefab, Vector3 cubePos)
    {
        ClipPlanePoints clipPoints = ClipPlanePoints.Instance;
        Camera          camera     = clipPoints.Camera;

        if (!clipPoints.CollidesTop(cubePos) &&
            !clipPoints.CollidesBottom(cubePos))
        {
            float cubeSpeed = Random.Range(
                m_minCubeSpeed, m_maxCubeSpeed);

            float firstSpawnTime = 0f;

            //Allows closer cubes to spawn more. If the cube is closer, maxRandMulti will be less.
            float spawnMulti = 0.05f * Mathf.Max(Vector3.Distance(clipPoints.NearUpperLeft, cubePos) /
                                                 Vector3.Distance(clipPoints.NearUpperLeft, clipPoints.FarUpperLeft), m_minSpawnTime);
            float maxSpawnTime = Mathf.Max(spawnMulti * m_maxSpawnTime, m_minSpawnTime);

            do
            {
                float spawnTime = Random.Range(firstSpawnTime, maxSpawnTime);
                yield return(new WaitForSeconds(spawnTime));

                firstSpawnTime = m_minSpawnTime;
                prefab.Clone(transform, cubePos, cubeSpeed * camera.transform.right);
            } while (true);
        }
    }