public IEnumerator ShowFeedback(int rating, int severity, Transform buttonPressed) { if (rating != -1) { // if rating == -1 then either the rating has not been set or this button should not have been possible to press var activeObject = Instantiate(GetActiveObject(rating)); activeObject.transform.SetParent(this.transform); var rect = activeObject.GetComponent <RectTransform>(); rect.offsetMin = Vector2.zero; rect.offsetMax = Vector2.zero; rect.localScale = Vector3.one; activeObject.SetActive(true); // Set position to the top of the button pressed transform.position = buttonPressed.position; // Animate the object _animation.Play(); yield return(new WaitForSeconds(_animation.clip.length)); // Fade out the feedback objects var ratingObjects = activeObject.GetComponentsInChildren <Transform>(); if (!_satisfactionDisplays) { _satisfactionDisplays = GameObject.Find("SatisfactionBar").GetComponent <SatisfactionDisplays>(); } if (!_incidentManager) { _incidentManager = GameObject.Find("TurnManager").GetComponent <IncidentManager>(); } float ratingImpact = (rating - 3) * severity; ratingImpact = ratingImpact > 0 ? ratingImpact * 0.2f : ratingImpact; _incidentManager.AddHappiness(ratingImpact); foreach (var feedbackTransform in ratingObjects) { feedbackTransform.SetParent(GameObject.Find("GameCanvas").transform); StartCoroutine(_satisfactionDisplays.TransitionTo(feedbackTransform, 0.5f, _incidentManager.GetActualHappiness())); // -3 as 3 indicates a neutral choice, so no change } } else { // This object would normally be set active before it is used, so lets force it to be inactive this.gameObject.SetActive(false); } }