Пример #1
0
    IEnumerator SpawnBehaviour()
    {
        while (!canSpawn)
        {
            Vector3    direction = new Vector3();
            Quaternion rotation  = new Quaternion();

            if (spawnPoint.x < 0f)
            {
                direction = Vector3.right;
                rotation  = Quaternion.Euler(0f, 0f, 0f);
            }
            else
            {
                direction = Vector3.left;
                rotation  = Quaternion.Euler(0f, 180f, 0f);
            }

            ObstacleController oc = Instantiate(spawnable, spawnPoint, rotation, container).GetComponent <ObstacleController>();

            oc.SetDirection(direction);
            oc.SetSpeed(speed);
            oc.SetDestroyOffset(spawnOffset);

            float cooldown = 1 / speed * xScale * Random.Range(minDist, maxDist);

            yield return(new WaitForSeconds(cooldown));
        }
    }