public void CreateCrate(float _water, float _potatoes, float _electricity, float _scrap, float _ductTape) { int baseRandSlot = (int)(UnityEngine.Random.value * m_crateDropPoints.Count); int successSlot = -1; for (int i = 0; i < m_crateDropPoints.Count; i++) { int slot = (baseRandSlot + i) % m_crateDropPoints.Count; if (m_crateSlots[slot] != 1) { successSlot = slot; } } if (successSlot == -1) { Debug.Log("Stacking crates, exiting."); return; } GameObject crate = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Drop_prefab")); m_crateSlots[successSlot] = 1; crate.name = "Drop_Crate_" + successSlot; crate.transform.position = new Vector3(m_crateDropPoints[successSlot].x, 15.0f, m_crateDropPoints[successSlot].z); crate.transform.Rotate(new Vector3(0.0f, 180.0f * UnityEngine.Random.value, 0.0f)); DropController dc = crate.GetComponent <DropController>(); dc.SetValues(_water <= 0 ? 0 : _water + GetRandomCrateChange(), _potatoes <= 0 ? 0 : _potatoes + GetRandomCrateChange(), _electricity <= 0 ? 0 : _electricity + GetRandomCrateChange(), _scrap <= 0 ? 0 : _scrap + GetRandomCrateChange(), _ductTape <= 0 ? 0 : _ductTape + GetRandomCrateChange(), successSlot); }
public void CollectCrate(DropController _crate) { AddAmount(Constants.WATER, _crate.water); AddAmount(Constants.POTATO, _crate.potatoes); AddAmount(Constants.ELECTRICITY, _crate.electricity); AddAmount(Constants.SCRAP, _crate.scrap); AddAmount(Constants.DUCTTAPE, _crate.ductTape); }