public void Remove(RandomBox box)
        {
            if (_randomBoxes.ContainsKey(box.Serial) == false)
            {
                Debug.LogError("Already box " + box.Serial + " Removed!");
                return;
            }

            _randomBoxes.Remove(box.Serial);
        }
示例#2
0
        public void CreateRandomBox(float xPosition, string itemId)
        {
            RandomBox boxInstance = Instantiate <GameObject>(_randomBoxPrefab).GetComponent <RandomBox>();

            boxInstance.ItemId = itemId;

            Vector2 createPosition = new Vector2(xPosition, Random.Range(0.5f, 1f));

            createPosition.y = -1.8f;
            boxInstance.transform.position = createPosition;

            //boxInstance.GetComponent<Rigidbody2D>().AddForce(Vector2.up * 10f);
        }
        public void Add(RandomBox box)
        {
            if (_randomBoxes.ContainsKey(box.Serial) == true)
            {
                throw new UnityException("Already box " + box.Serial + " Added!");
            }

            int newSerial = _serialIssuer.Get();

            box.SetSerial(newSerial);

            _randomBoxes.Add(newSerial, box);
        }
        public void Use()
        {
            var interactiveBoxes = (from box in _randomBoxes.Values
                                    where box.IsInteractive == true
                                    orderby box.Serial descending
                                    select box);

            if (interactiveBoxes.Count() == 0)
            {
                return;
            }

            RandomBox boxToUse = interactiveBoxes.ToArray()[0];

            boxToUse.Use();
        }