private void OnTriggerEnter(Collider other) { RemoveDestroyedObjects(); DropZoneObject d = other.GetComponent <DropZoneObject>(); if (d == null) { return; } if (AddObject(d)) { Destroy(d.gameObject); SetMaterialColor(validColor); SetMaterialColor(defaultColor, 2f); SetScale(3); SetScale(1, 3); } else { invalidObjects.Add(d.gameObject); SetMaterialColor(invalidColor, 0); } }
/// <summary> /// Attempt to add an object to storage. /// </summary> /// <param name="other">Object to add</param> /// <returns>true if addition was successful, false otherwise.</returns> private bool AddObject(DropZoneObject other) { if (!storage.ContainsKey(other.ObjectID) || storage[other.ObjectID].Full) { return(false); } // increment the object's counter storage[other.ObjectID].Add(); // recalculate progress to completion progress = (float)storage.Values.Sum((x) => x.Count) / storage.Values.Sum((x) => x.Capacity); // activate if full if (!allowSingleObjectFromList) { if (activated = storage.Values.All((x) => x.Full) && !triggered) { ActivateDropZone(); } } else { if (storage.Values.Count > 0 && !triggered) { ActivateDropZone(); } } return(true); }