- Home /
My Method won't take in a class.
I'm doing this tutorial on Dialogue, and decided to try doing a bit extra, but I can't get the End Dialogue method to take in the Dialogue class. Here's my code:`using System.Collections; using System.Collections.Generic; using UnityEngine;
[System.Serializable] public class Dialogue {
 [TextArea(3,10)]
 public string[] sentences;
 public string name;
}
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DialogueManager : MonoBehaviour {
     //Queue do first in first out
     private Queue<string> sentences;
 
 
     void Start () {
 
         sentences = new Queue<string>();
 
     }
 
     public void StartDialogue (Dialogue dialogue) {
 
         Debug.Log (dialogue.name + " will see you now");
 
         sentences.Clear (); // clears sentences
 
         foreach (string sentence in dialogue.sentences) // a foreach loop. self explanatory
         {
                                         
             sentences.Enqueue(sentence);// for each sentence in Dialogue.sentences, this loop puts
                                         // it into the Queue sentences, identifying them as sentence
         }
 
         DisplayNextSentence ();
     }
     public void DisplayNextSentence() {
 
         if (sentences.Count == 0) {
 
             EndDialogue (); // find out how to make this take in Dialogue (problem is here)
             return; // stops the function being called, in this case, stopping another sentence from
                     // being loaded if there are none
         }
         string sentence = sentences.Dequeue (); // dequeues the next sentence (hence the function name
                                                 // and store it in a string called sentence
         Debug.Log(sentence);
 
     }
     void EndDialogue(Dialogue dialogue) {
         
         Debug.Log(dialogue.name + " is leaving now");
 
     }
 
 }
 
Answer by Cornelis-de-Jager · Apr 08, 2018 at 10:21 PM
You never pass a valid argument into End Dialog. I assume you want the same dialogue referenced in the StartDialog function. Try this:
     public void StartDialogue (Dialogue dialogue) {
  
          Debug.Log (dialogue.name + " will see you now");
  
          sentences.Clear (); // clears sentences
  
          foreach (string sentence in dialogue.sentences) // a foreach loop. self explanatory
          {
                                          
              sentences.Enqueue(sentence);// for each sentence in Dialogue.sentences, this loop puts
                                          // it into the Queue sentences, identifying them as sentence
          }
  
          DisplayNextSentence (dialogue);
      }
      public void DisplayNextSentence(Dialogue dialogue) {
  
          if (sentences.Count == 0) {
  
              EndDialogue (dialogue); // find out how to make this take in Dialogue (problem is here)
              return; // stops the function being called, in this case, stopping another sentence from
                      // being loaded if there are none
          }
          string sentence = sentences.Dequeue (); // dequeues the next sentence (hence the function name
                                                  // and store it in a string called sentence
          Debug.Log(sentence);
  
      }
Answer by foureyes44 · Apr 08, 2018 at 10:22 PM
Fixed it by adding the parameters to the method that was calling the method.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to initialize a Color array to a key color, once in code hit frequently. 0 Answers
Material doesn't have a color property '_Color' 4 Answers
Define pixels 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                