Home > database >  Certain names do not exist in current context in Unity
Certain names do not exist in current context in Unity

Time:04-26

I'm trying to create a unity script that plays dialogue using the third party program Ink. and when I attempt to run the program these three errors constantly appear:

Assets\C# Scripts\DialogueManager.cs(37,13): error CS0103: The name 'InputManager' does not exist in the current context Assets\C# Scripts\DialogueManager.cs(57,13): error CS0103: The name 'current' does not exist in the current context Assets\C# Scripts\DialogueManager.cs(57,13): error CS0103: The name 'current' does not exist in the current context

and here's the code itself below; it's a couple lines long but the error messages show the relevant lines:

1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using TMPro;
5 using Ink.Runtime;
6 
7 public class DialogueManager : MonoBehaviour
8 {
9     [Header("Dialogue UI")]
10    [SerializeField] private GameObject dialoguePanel;
11     [SerializeField] private TextMeshProUGUI dialgoueText;
12 
13     private Story currentStory;
14     private bool dialogueIsPlaying;
15 
16     private static DialogueManager instance;
17 
18    private void Awake()
19     {
20         instance = this;
21     }
22     public static DialogueManager GetInstance()
23     {
24         return instance;
25     }
26    private void Start()
27     {
28         dialogueIsPlaying = false;
29         dialoguePanel.SetActive(false);
30     }
31     private void Update()
32     {
33         if (!dialogueIsPlaying)
34         {
35             return;
36         }
37         if (InputManager.GetInstance(). GetSubmitPressed())
38         {
39             ContinueStory();
40        }
41     }
42 
43     public void EnterDialogueMode(TextAsset inkJSON)
44     {
45         currentStory = new Story(inkJSON.text);
46         dialogueIsPlaying = true;
47         dialoguePanel.SetActive(true);
48 
49     }
50     private void ExitDialogueMode()
51     {
52         dialogueIsPlaying = false;
53        //SCENE MANAGER GO OFF SCENE TO WORLD
54    }
55     private void ContinueStory()
56     {
57         if (current.Story.canContinue)
58         {
59             dialogueText.text = currentStory.Continue();
60         }
61         else
62         {
63             ExitDialogueMode();
64         }
65     }
66 }

I've got no idea how to fix this issue and am pretty new to coding so help would be much appriciated!

CodePudding user response:

You need to A. Define InputManager, and B. you should change current to currentStory

That may not be the only issue, but that will be a start

CodePudding user response:

This is your problem (Line 57):

you wrote current.Story.canContinue instead of currentStory.canContinue

private void ContinueStory()
56     {
57         if (current.Story.canContinue)
58         {
59             dialogueText.text = currentStory.Continue();
60         }
61         else
62         {
63             ExitDialogueMode();
64         }
65     }
  • Related