public Collectable SpawnAllCollectables(SampoProductType type) { foreach (Collectable collectable in _collectables) { InitCollectable(collectable, type); } return(_collectables[0]); }
public Collectable SpawnCollectable(SampoProductType type, bool launchToPosition) { // True: the collectable flies to its position // False: the collectable just appears at its position _launchToPosition = launchToPosition; return(SpawnCollectable(type)); }
public void SpawnCollectables(SampoProductType type, int amount, float interval) { _spawnMultiple = true; _collType = type; _leftToSpawn = amount; _spawnInterval = interval; // Ensures that one collectable is spawned immediately _elapsedTime = interval; }
public void SpawnCollectables(SampoProductType type, int amount, float interval, bool launchToPosition) { // True: the collectable flies to its position // False: the collectable just appears at its position _launchToPosition = launchToPosition; _randomProduct = false; SpawnCollectables(type, amount, interval); }
public void Init(SampoProductType sampoProductType, Sampo sampo, Vector3 spawnPosition) { _sampoProductType = sampoProductType; _sampo = sampo; transform.position = spawnPosition; _fadeOutTimeModified = _fadeOutTimeBase + Random.Range(-_startFadingOutTimeVariance, _startFadingOutTimeVariance); _fadeOutTimeCountdown = _fadeOutTimeModified; GetComponent <Renderer>().material.color = _originalColor; _newColor = _originalColor; _startFadingOutTimeCounter = 0f; }
private void ResetSpawning() { _collType = SampoProductType.None; _spawnMultiple = false; _randomProduct = false; _elapsedTime = 0; _leftToSpawn = 0; if (EndGenerating != null) { EndGenerating(); } }
public void SpawnSampoProduct(SampoProductType sampoProduct) { switch (sampoProduct) { case SampoProductType.Grain: _sampoProduct = _sampo._grainPool.GetPooledObject(); break; case SampoProductType.Salt: _sampoProduct = _sampo._saltPool.GetPooledObject(); break; case SampoProductType.Gold: _sampoProduct = _sampo._goldPool.GetPooledObject(); break; } if (_sampoProduct != null) { _sampoProduct.Init(sampoProduct, _sampo, transform.position); #region Scaling // Scale the sampo product randomly, to make them look more unique. float productScale = 1.5f; if (_sampoProductType == SampoProductType.Grain) { productScale = Random.Range(1.5f, 3f); } if (_sampoProductType == SampoProductType.Salt) { productScale = Random.Range(1.5f, 3f); } _sampoProduct.transform.localScale = new Vector3(productScale, productScale, productScale); #endregion // Calculate the direction toward which the sampo product should be launched towards. Vector3 launchDirection = (transform.position - _sampoMiddle.transform.position) + new Vector3(Random.Range(-_randomDirectionMultiplier, _randomDirectionMultiplier), 0f, Random.Range(-_randomDirectionMultiplier, _randomDirectionMultiplier)); launchDirection.y = 0f; // Null the vertical direction. launchDirection.Normalize(); // Launch the sampo product along the launchDirection vector. _sampoProduct.GetComponent<Rigidbody>().AddForce(launchDirection * (_launchForceMultiplier + Random.Range(-_launchForceVariance, _launchForceVariance)), ForceMode.Impulse); } }
public void Init(SampoProductType type) { Type = type; switch (Type) { case SampoProductType.Grain: { _collectableObject = _grainModel; _scoreType = Scorekeeper.ScoreType.CollectableGrain; break; } case SampoProductType.Salt: { _collectableObject = _saltModel; _scoreType = Scorekeeper.ScoreType.CollectableSalt; break; } case SampoProductType.Gold: { _collectableObject = _goldModel; _scoreType = Scorekeeper.ScoreType.CollectableGold; break; } default: { _collectableObject = null; Debug.LogError("Invalid collectable type."); break; } } SetDefaults(); _motionCompleted = false; _elapsedTime = 0; State = CollectableState.Idle; }
public Collectable SpawnCollectable(SampoProductType type) { Collectable collectable = GetRandomItemFromPool(); if (collectable != null) { if (_randomProduct) { type = GetRandomProductType(); } InitCollectable(collectable, type); } else { Debug.LogWarning("No collectables in pool."); } return(collectable); }
private void InitCollectable(Collectable collectable, SampoProductType type) { if (type == SampoProductType.None) { Debug.LogError ("Trying to initialize a collectable with type None."); return; } collectable.ShowCollectableObject(false); collectable.Init(type); collectable.ShowCollectableObject(true); collectable.gameObject.SetActive(true); if (_launchToPosition) { // Launches the collectable from the spawner's position // to the collectable's own target position collectable.LaunchToPosition (transform.position, _launchSpeed); } }