Failed to call function "" of class "". Calling function "" with no parameters but the function requires 1
I'm working on a prototype for a project I'm planning out right now and I'm working on a basic dialogue system. I've decided to have a manager for the text that the NPC you are talking to says. I have a function called "ShowSubtitles" where when called, it sets the subtitles box to be active and changes the text in the subtitles to whatever parameter you put for the text. Right now in the script for the NPC's dialogue I'm trying to have him say something, wait 5 seconds, then say the next thing. I've set the waiting up with a coroutine but I haven't really used them before. Once I try to call the wait coroutine with the parameter of how long I want it to wait, I get the error "Failed to call function "wait" of class "Dialogue". Calling function "wait" with no parameters but the function requires 1." [code]
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LucasSimmsDialogue : MonoBehaviour {
private SubtitlesManager sMan;
void Start() {
sMan = FindObjectOfType<SubtitlesManager>();
StartCoroutine( "Wait" );
}
void OnCollisionStay2D(Collision2D other)
{
if( other.gameObject.tag == "Player")
{
if ( Input.GetKeyUp(KeyCode.E) )
{
InitiateConversation();
}
}
}
IEnumerator Wait(int time)
{
Debug.Log( "Waiting.." );
yield return new WaitForSeconds(time);
}
void InitiateConversation()
{
sMan.ShowSubtitles( "Name\'s Lucas Simms, town sheriff. And Mayor too, when the need arises." );
StartCoroutine(Wait(5));
sMan.ShowSubtitles( "I don\'t why, but I like you, boy! Something tells me you're all right. So welcome to Megaton! Just holler if you need something." );
}
}[/code]
Answer by FortisVenaliter · Jul 17, 2017 at 09:11 PM
The error is coming from your call in Start(), not your call in InitiateConversation(). The latter is used correctly whereas the first is in fact missing an argument.
Thank you very much! I didn't realize that was the error and now looking back on it, that is pretty stupid.
Answer by mbhagat · Apr 05, 2018 at 02:11 PM
In your Coroutineyou have defined wait time as argument. IEnumerator Wait(int time) { Debug.Log( "Waiting.." ); yield return new WaitForSeconds(time); }
You are trying to call it without argument . StartCoroutine( "Wait" ); Either supply argument or remove it from Coroutine.
Your answer
Follow this Question
Related Questions
WaitForSeconds not working in C# 1 Answer
Trouble with coroutine 0 Answers
Why do I keep getting this error? 1 Answer
[c sharp] why isn't my player dying when it touches the truck? 1 Answer
UnityEngine.Component could be found 0 Answers