Unity游戏开发报错:调用almostDone(string)缺少对应实参的解决咨询
Hey there! Let's break down and fix that error you're hitting in your game code.
What's Causing the Error?
The error message says it plainly:
There is no argument given that corresponds to the required formal parameter 'input' of 'Gamescript.almostDone(string)'
Your almostDone method is defined to require a string parameter named input, but when you call it in the if (input == "ls") block with almostDone();, you're not passing any value to it. The compiler can't fill in this missing required value automatically, so it throws this error.
How to Fix It
Since you're already inside the firstEntered method which has access to the input string variable, you just need to pass that variable to almostDone when you call it.
Here's the corrected snippet of your code:
if (input == "ls") { Terminal.WriteLine("Listing Bank Logs:30m"); Terminal.WriteLine("New_Transaction to 921831"); Terminal.WriteLine("Password_Update to Sonnie"); Terminal.WriteLine("New_Transaction to 921831"); Terminal.WriteLine(""); Terminal.WriteLine("REMINDER: Once you've found the password,"); Terminal.WriteLine("run: Email -i [Pass] Garris@Exuno.com"); almostDone(input); // Pass the existing input parameter here } else { Terminal.WriteLine ("Unrecognized Command. Try again:"); }
Alternative Option (If You Don't Need the Input Parameter)
If the almostDone method doesn't actually rely on the input value to function, you could modify the method definition to make the parameter optional instead:
void almostDone(string input = "") { // Your existing almostDone code logic here }
This lets you call almostDone(); without arguments (it will use the default empty string value for input). But based on your current code flow, passing the existing input variable is the cleaner, more logical fix.
内容的提问来源于stack exchange,提问作者PricklyTrees

