private void AddToUI(CollectableInfo c) { if (c.item == "hamer") { currentHamers++; } else if (c.item == "plank") { currentPlanks++; } collectableUI.LinkInventory(); }
private void SpawnCollectables(Transform[] lanes, float spanX) { if (_collectables == null || _collectables.Length <= 0) { return; } for (int i = 0; i < mCollectables.Count; ++i) { mCollectables[i].Deactivate(); } mCollectables.Clear(); float currPosX = -spanX / 2; float endPosX = spanX / 2; int minSkip = 5; int maxSkip = 10; while (currPosX < endPosX) { bool skip = (Random.Range(0, 2) == 0); if (skip) { currPosX += _collectablesDistance * Random.Range(minSkip, maxSkip + 1); continue; } Transform lane = lanes[Random.Range(0, lanes.Length)]; CollectableInfo selectedCollectable = _collectables[Random.Range(0, _collectables.Length)]; int numSpawns = Random.Range(selectedCollectable.pMinCount, selectedCollectable.pMaxCount + 1); for (int i = 0; i < numSpawns; ++i) { GameObject coll = selectedCollectable.pCollectablePool.GetObject(); mCollectables.Add(coll.GetComponent <Collectable>()); Vector3 newPos = lane.localPosition + new Vector3(currPosX, 0, 0); coll.transform.parent = transform; coll.transform.localPosition = newPos; currPosX += _collectablesDistance; if (currPosX >= endPosX) { break; } } } }
private void Collect(CollectableInfo collectable) { inventory.AddInventory(collectable); }
public void AddInventory(CollectableInfo collectable) { inventory.Add(collectable); AddToUI(collectable); }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("RopeBase")) { _soundEmmiter.ExplosionSound(); _hand.Die(); var otherAnimator = other.GetComponent <Animator>(); otherAnimator.Play("RopeExplosion"); var timeOfAnimation = otherAnimator.GetCurrentAnimatorClipInfo(0).Length; other.GetComponent <Base>().DestroyThis(); } if (other.CompareTag("Collectable")) { CollectableInfo otherInfo = other.GetComponent <CollectableInfo>(); if (otherInfo.petType == "Dog") { _gameVars.dogsCollected += 1; if (_gameVars.dogsCollected >= _customPrice.dogPrice) { _soundEmmiter.UnlockPetSound(); } else { _soundEmmiter.PetSound(); } PlayerPrefs.SetInt("Dog", _gameVars.dogsCollected); } else if (otherInfo.petType == "Monkey") { _gameVars.monkeysCollected += 1; PlayerPrefs.SetInt("Monkey", _gameVars.monkeysCollected); if (_gameVars.monkeysCollected >= _customPrice.monkeyPrice) { _soundEmmiter.UnlockPetSound(); } else { _soundEmmiter.PetSound(); } } else if (otherInfo.petType == "Godling") { _gameVars.godlingsCollected += 1; PlayerPrefs.SetInt("Godling", _gameVars.godlingsCollected); if (_gameVars.godlingsCollected >= _customPrice.godlingPrice) { _soundEmmiter.UnlockPetSound(); } else { _soundEmmiter.PetSound(); } } else if (otherInfo.petType == "Ghost") { _gameVars.ghostCollected += 1; if (_gameVars.ghostCollected >= _customPrice.ghostPrice) { _soundEmmiter.UnlockPetSound(); } else { _soundEmmiter.PetSound(); } PlayerPrefs.SetInt("Ghost", _gameVars.ghostCollected); } else if (otherInfo.petType == "Fish") { _gameVars.fishCollected += 1; if (_gameVars.fishCollected >= _customPrice.fishPrice) { _soundEmmiter.UnlockPetSound(); } else { _soundEmmiter.PetSound(); } PlayerPrefs.SetInt("Fish", _gameVars.fishCollected); } Destroy(other.gameObject); } }