// Attempts to collect an object public bool Collect( Collectable other ) { if ( maxCollectionSize <= collection.Count ) { return false; } if ( false == collection.Contains ( other ) ) { other.audio.Play (); if ( other.itemType == Collectable.ItemType.GhostKey) { AppManager.Instance.humanWinScreen.SetActive(true); AppManager.Instance.BeginGameOver(); } else { AppManager.Instance.DisplayMessage("This is just a " + other.name + ". I'll Keep Looking."); } collection.Add ( other ); other.Collected (); if ( makeAttachPointParent ) { other.gameObject.transform.parent = attachPoint; other.transform.position = Vector3.zero; other.transform.localPosition = Vector3.zero; } else { other.transform.position = attachPoint.position; other.transform.localPosition = Vector3.zero; } } return true; }
protected void Update() { if (_pendingCollection) { _pendingCollection.Collected(); if (OnCollect != null) { OnCollect(_pendingCollection); } _pendingCollection = null; } }
// Update is called once per frame void Update() { if (testTrash != null && carrying < capacity) { //Set Collectable object's parentCollector to this object if close enough if ((this.transform.position - testTrash.transform.position).magnitude < range) { if (testTrash.collected == false) { Debug.Log("Collected!"); testTrash.Collected(this); //Increment count for currently carried objects carrying++; } } } }