using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; using System.Linq; //Allow counting in a list public class NPCDialogueArea3 : MonoBehaviour { public PlayerInventory playerInventory; private bool playerInRange = false; //Variable so that the player has to be close to interact private bool dialogueActive = false; public GameObject dismiss; //Allow ui text to be assigned to this in the inspector public GameObject dialogueMessage; public GameObject dialoguePanel; bool missionComplete = false; //To know when to change from mission text to complete text public GameObject missionCompleteMessage; public GameObject interactPrompt; [SerializeField] GameObject missionReward; void Start() { missionReward.SetActive(false); //Wait until player has completed mission to get the reward interactPrompt.SetActive(false); } void itemCheck() //Check how much wood the player is holding and if it's enough to complete the mission { int woodCount = playerInventory.inventory.Count(item => item == "wood"); //Get the number of wood that is in the inventory list (player inventory) if (woodCount == 3 || woodCount > 3) //Check if player has 3 or more wood { missionComplete = true; } } // Update is called once per frame void Update() { if (playerInRange && Input.GetKeyDown(KeyCode.E)) //Run if player is in range and presses "e" { dialogueActive = true; interactPrompt.SetActive(false); } if ((dialogueActive == true) && (missionComplete == false)) //First message shown to player { dismiss.SetActive(true); dialogueMessage.SetActive(true); dialoguePanel.SetActive(true); } if ((dialogueActive == true) && (missionComplete == true)) //Message shown to player after quest is completed { dismiss.SetActive(true); dialoguePanel.SetActive(true); missionCompleteMessage.SetActive(true); //Remove the wood from the player after mission completion: int removed = 0; while (removed < 3 && playerInventory.inventory.Contains("wood")) { playerInventory.inventory.Remove("wood"); removed++; } missionReward.SetActive(true); //Spawn in the gold reward for the player } if ((dialogueActive == true) && Input.GetMouseButtonDown(0) || (dialogueActive == false)) //Allow the player to click to make the text dissapear { dismiss.SetActive(false); dialogueMessage.SetActive(false); dialoguePanel.SetActive(false); dialogueActive = false; missionCompleteMessage.SetActive(false); } } void OnTriggerEnter2D() { playerInRange = true; interactPrompt.SetActive(true); itemCheck(); //Check player items when in range of NPC } void OnTriggerExit2D() { playerInRange = false; interactPrompt.SetActive(false); } }