No overload for method `Move' takes `1' arguments
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DialogueManager : MonoBehaviour { public static DialogueManager Instance { get; set; }
public List<string> dialogueLines = new List<string>();
public string npcName;
public GameObject dialoguePanel;
void Awake () {
if (Instance != null && Instance != this) {
Destroy (gameObject);
}
else
{
Instance = this;
}
}
public void AddNewDialogue(string[] lines, string npcName)
{
dialogueLines = new List<string>();
foreach (string line in lines)
{
dialogueLines.Add(line);
}
this.npcName = npcName;
Debug.Log (dialogueLines.Count);
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NPC : Interactable { public string[] dialogue; public string Name;
public override void Interact()
{
DialogueManager.Instance.AddNewDialogue(dialogue); //getting error here
Debug.Log ("Interacting with NPC.");
}
}
Answer by Legend_Bacon · Mar 14, 2018 at 05:17 PM
Hello there,
You call "AddNewDialogue" by passing in your variable "dialogue", but the function is expecting TWO arguments, not ONE. It expects an array of strings called "lines", as well as a string called "npcName".
The fix would be to pass in your NPC name as well as the dialogue:
DialogueManager.Instance.AddNewDialogue(dialogue, myNpcName);
I hope that helps!
Cheers,
~LegendBacon
I'm adding (dialogue, npcName) and it's saying it doesn't exist in the current context?
You may have named the variable differently on your NPC script. Your code above seems to indicate that you need to use "Name" ins$$anonymous$$d of "npcName".
But basically, it's whatever string variable holds the name of your NPC.
I have made an explanation of Overloads here applied to 'Instantiate' but the reasoning is the same.
In a nutshell, arguments to a Function must match exactly in type.
When you call a function (or Invoke) you do not repeat the arguments as they are written in the constructor, for their name... you simply feed in what it wants according to type... it can be from ANY similarly typed variable. If you dont quite understand this you could look at it here .
~
There is also a wealth of information to be found :
Your answer
Follow this Question
Related Questions
Need this Object to move faster and faster after time! 2 Answers
How to move object a from in front of object b to in front of object c and transfer orientation? 1 Answer
My player moves diagonally when you press two keys at once 0 Answers
help with multitouch buttons 0 Answers
Generic arrays? 1 Answer