Exemplo n.º 1
0
    public void SpawnNumber(double content, Vector3 location)
    {
        _accumulator += content;

        if (!_poolController.ObjectsAvailable() ||
            !(Time.time - _lastSpawn > _spawnDelay) ||
            _accumulator < 11)
        {
            return;
        }

        var instance = _poolController.Spawn() as FloatingNumber;

        if (!instance)
        {
            throw new NullReferenceException();
        }

        Vector2 screenPosition = Camera.main.WorldToScreenPoint(
            new Vector3(
                location.x + Random.Range(-.2f, .2f),
                0f,
                location.z + Random.Range(-.2f, .2f)
                ));

        instance.transform.SetParent(_canvas.transform, false);
        instance.transform.position   = screenPosition;
        instance.transform.localScale = new Vector3(1, 1, 1);
        instance.SetNumber(_accumulator);
        instance.StartPlayback();
        _accumulator = 0;
        _lastSpawn   = Time.time;
        PoolCount    = _poolController.ObjectCount();
    }