private void HandleRetrievingObject() { //If the user press the interact button if (Input.GetKeyDown(KeyCode.Z)) { //If the bird is not carrying anything and there is an object that can be retrieved if (m_carriedObject == null) { Retrievable retrievedObject = GetValidRetrievable(); if (retrievedObject != null) { //Carry the first object in the retrievable list m_carriedObject = retrievedObject; m_retrievables.Remove(retrievedObject); //Make the object a child of bird so that it follows m_carriedObject.transform.parent = transform; //Center the position of the object m_carriedObject.transform.localPosition = Vector3.zero; //Triggers the callback on the object when retrieved m_carriedObject.OnRetrieved(); //Add the object to the bubble m_bubble.SetActive(true); m_bubble.GetComponent <SpriteRenderer>().sprite = m_carriedObject.GetComponent <SpriteRenderer>().sprite; } } else { //Remove the bubble m_bubble.SetActive(false); //Triggers the callback on the object when un-retrieved m_carriedObject.OnUnretrieved(); //Remove the object from child m_carriedObject.transform.parent = null; //Remove this m_carriedObject = null; } } }
/// <summary> /// Notify the bird that the object is retrievable /// </summary> /// <param name="retrievable"></param> public void UnregisterFromRetrievables(Retrievable retrievable) { m_retrievables.Remove(retrievable); }
/// <summary> /// Notify the bird that the object is retrievable /// </summary> public void RegisterToRetrievables(Retrievable retrievable) { m_retrievables.Add(retrievable); }