/*A function that determines the context of a click given the name of the item clicked on.*/ private void ParseItemClicks(string name) { //first, get the Item Item itemClicked = new Item(); itemClicked = FindItemByName(name); //find all game objects of type Person in the scene and set their animations to idle GameObject[] people = GameObject.FindGameObjectsWithTag("Person"); for (int i = 0; i < people.Length; i++) { AnimatorManager am = people[i].GetComponent <AnimatorManager>(); am.ResetToIdle(); } //if the player is attempting to look at an item if (GameManager.currentAction == 2) { //update the dialogue box with the item's description GameManager.UpdateDialogueText(itemClicked.ItemDescription); } //if the player is attempting to talk to an item else if (GameManager.currentAction == 3) { if (GameManager.levelIndex == 0) { //dont let them GameManager.UpdateDialogueText("You can't talk to this."); } } //if the player is attempting to pick up an item else if (GameManager.currentAction == 4) { //find the gameobject to be removed from the scene GameObject objectToBeDestroyed = GameObject.Find(name); //reflect that they picked the item up in the dialogue box GameManager.UpdateDialogueText("You picked up: " + name); //add the item to the player's inventory GameManager.inventory.Add(itemClicked); Debug.Log("Added " + itemClicked.ItemName + " to inventory"); GameManager.UpdateInventory(objectToBeDestroyed.GetComponent <Image>().sprite); //destroy the gameobject pertaining to the Item Destroy(GameObject.Find(name)); //reset the action text window GameManager.UpdateActionText(" "); GameManager.ChangeCurrentAction(2); } //if the player isnt trying to pick up an item, they're probably trying to look at it if (GameManager.currentAction != 4) { //so give the description GameManager.UpdateDialogueText(itemClicked.ItemDescription); } }
//private void ParseInventoryClicks(string name) //{ // Item itemClicked = new Item(); // if (GameManager.currentAction == 0) // { // itemClicked = GameManager.inventory[GameManager.ParseClick(name)]; // ItemClickHandler.hasSelectedItem = true; // GameManager.UpdateActionText("Give " + itemClicked.ItemName + " to whom?"); // lastItem = itemClicked; // } //} /*A function that determines the context of a click given the name of the person clicked on.*/ private void ParsePersonClicks(string name) { //first, get the Person Person personClicked = new Person(); personClicked = FindPersonByName(name); //if (GameManager.currentAction == 0) //{ // if (!ItemClickHandler.hasSelectedItem) // { // GameManager.UpdateDialogueText("I wouldn't, if I were you."); // } // else if (ItemClickHandler.hasSelectedItem) // { // GameManager.UpdateDialogueText(lastItem.ValidGive); // } // ItemClickHandler.isGiving = false; //} //else if (GameManager.currentAction == 2) //{ // GameManager.UpdateDialogueText(personClicked.PersonLook); //} //else if (GameManager.currentAction == 3) //{ // int determinant; // determinant = (GameManager.levelIndex % 2); // if (determinant >= 0) // { // GameManager.UpdateDialogueText(personClicked.PersonTalk0); // } // else // { // GameManager.UpdateDialogueText(personClicked.PersonTalk1); // } //if the player is trying to look at the person if (GameManager.currentAction == 2) { //update the dialogue box with their description GameManager.UpdateDialogueText(personClicked.PersonLook); //reset default action to talk GameManager.currentAction = 3; //wipe the action text window previous = ""; GameManager.UpdateActionText(""); //reset the person's animation to idle, because the player isn't talking to them AnimatorManager am = gameObject.GetComponent <AnimatorManager>(); am.ResetToIdle(); } //if the player is attempting to pick the person up else if (GameManager.currentAction == 4) { //dont let them GameManager.UpdateDialogueText("\"Um. Please put me down.\""); AnimatorManager am = gameObject.GetComponent <AnimatorManager>(); am.Talk(); GameManager.currentAction = 3; previous = ""; GameManager.UpdateActionText(""); } else { //the default case -- talk to the person //find the animator manager of the person clicked on, then find all the animator managers //attached to other people in the scene. if there is no match, set that animator to idle //and set the one just clicked on to talk. AnimatorManager am = gameObject.GetComponent <AnimatorManager>(); GameObject[] people = GameObject.FindGameObjectsWithTag("Person"); for (int i = 0; i < people.Length; i++) { AnimatorManager otherAM = people[i].GetComponent <AnimatorManager>(); if (otherAM != am) { otherAM.ResetToIdle(); } } am.Talk(); //simple math to determine whether or not the scene index is odd or even int determinant; determinant = (GameManager.levelIndex % 2); //if the scene index is even if (determinant >= 0) { //make the person say their first talk option GameManager.dialogueText.text = personClicked.PersonTalk0; //add all questions and answers for the person to lists List <string> questions = new List <string>(); List <string> answers = new List <string>(); questions.Add(personClicked.PersonQuestion0); questions.Add(personClicked.PersonQuestion1); answers.Add(personClicked.PersonAnswer0); answers.Add(personClicked.PersonAnswer1); Debug.Log(questions[0]); Debug.Log(questions[1]); Debug.Log(answers[0]); Debug.Log(answers[1]); //make buttons for each question foreach (string question in questions) { Button objectToBeInstantiated; Text buttonText; objectToBeInstantiated = Instantiate(buttonPrefab, itemButtonHolder.transform.position, Quaternion.identity); objectToBeInstantiated.transform.parent = itemButtonHolder.transform; objectToBeInstantiated.transform.localScale = Vector3.one; Color c; c = objectToBeInstantiated.GetComponent <Image>().color; c.a = 0; objectToBeInstantiated.GetComponent <Image>().color = c; buttonText = objectToBeInstantiated.GetComponentInChildren <Text>(); buttonText.text = question; buttonText.fontSize = 20; buttonText.fontStyle = FontStyle.Italic; objectToBeInstantiated.onClick.AddListener(() => GameManager.UpdateDialogueText(answers[questions.IndexOf(question)])); objectToBeInstantiated.onClick.AddListener(() => itemsForDestruction = GameObject.FindGameObjectsWithTag("Destroy")); objectToBeInstantiated.onClick.AddListener(() => DestroyButtons()); } } //if the scene index is odd, make the person say their second talk option else { GameManager.dialogueText.text = personClicked.PersonTalk1; } } }