Hey guys I kinda need some help.... It gives me error at the first one on line 13 and at the second one at line 29 Please help me I don't know how to resolve this Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class NPC : Interactable { public string[] dialogue; public string npcName; public override void Interact() { DialogueSystem.Instance.AddNewDialogue(dialogue, npcName); Debug.Log("Interacting with NPC."); } } Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class Interactable : MonoBehaviour { [HideInInspector] public NavMeshAgent playerAgent; private bool hasInteracted; public virtual void MoveToInteraction(NavMeshAgent playerAgent) { hasInteracted = false; this.playerAgent = playerAgent; playerAgent.stoppingDistance = 3f; playerAgent.destination = transform.position; } void Update() { if (playerAgent != null && !playerAgent.pathPending) { if (!hasInteracted && playerAgent.remainingDistance <= playerAgent.stoppingDistance) { Interact(); hasInteracted = true; } } } public virtual void Interact() { Debug.Log("Interacting with base class."); } } It gives me error at the first one on line 13 and at the second one at line 29 please help me I don't know how to resolve this
Use code tags, we're not gonna count lines to find line 13 or line 29. Also you included several scripts, so indicate which of the scripts those errors refer to as well.
OK, so on the first one, DialogueSystem.Instance is clearly null. Is there a DialogueSystem in the scene somewhere, and is it on an object that's active? Otherwise, can you show the code for DialogueSystem?
I can show the code : Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DialogueSystem : MonoBehaviour { public static DialogueSystem Instance { get; set; } public GameObject dialoguePannel; public string npcName; public List<string> dialogueLines = new List<string>(); Button continueButton; Text dialogueText, nameText; int dialogueIndex; void Awake() { continueButton = dialoguePannel.transform.Find("Continue").GetComponent<Button>(); dialogueText = dialoguePannel.transform.Find("text").GetComponent<Text>(); nameText = dialoguePannel.transform.Find("Name").GetChild(0).GetComponent<Text>(); continueButton.onClick.AddListener(delegate { ContinueDialogue(); }); dialoguePannel.SetActive(false); if(Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } } public void AddNewDialogue(string[] lines, string npcName) { dialogueIndex = 0; dialogueLines = new List<string>(lines.Length); dialogueLines.AddRange(lines); this.npcName = npcName; CreateDialogue(); } public void CreateDialogue() { dialogueText.text = dialogueLines[dialogueIndex]; nameText.text = npcName; dialoguePannel.SetActive(true); } public void ContinueDialogue() { if (dialogueIndex < dialogueLines.Count - 1) { dialogueIndex++; dialogueText.text = dialogueLines[dialogueIndex]; } else { dialoguePannel.SetActive(false); } } }
I'd start by adding a Debug.Log("here") line next to line 32 of DialogueSystem, to ensure that that line is being executed (and that it's happening before your other script is running).