我一直在尝试构建以下Text Adventure并且遇到了一个错误,我无法弄清楚如何解决。错误是:
Assets / My_Scripts / MH_Script.cs(19,23):错误CS1501:方法Add'需要2'参数
以下是MH_Script.cs
的开头代码,由于这是一个文本冒险,因此列表相当长。
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MH_Script {
public static List<MH_ScriptManager> sList = new List<MH_ScriptManager>();
public MH_Script(){
sList.Add("start", "You awaken in a sweltering room....
sList
以相同的方式添加了更多字符串,后跟:
public string SendScript(string state){
string returnthis = "";
foreach(MH_ScriptManager sm in sList){
if(sm.getState() == state){
returnthis = sm.getStory();
}
}
return returnthis;
}
}
这里是MH_ScriptManager
:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MH_ScriptManager{
public Helpers.STATE gState;
public string gScript;
public string getCurrentState(){
return gState;
}
public MH_ScriptManager (string state, string script){
gState = Helpers.ParseEnum<Helpers.STATE>(state);
gScript = script;
}
public string getStory(){
return gScript;
}
public string getState(){
return gState.ToString();
}
public void setStory(string script){
gScript = script;
}
public void setState(string state){
gState = Helpers.ParseEnum<Helpers.STATE>(state);
}
public bool compareStatetoString(string compare){
if (gState == Helpers.ParseEnum<Helpers.STATE> (compare))
return true;
else
return false;
}
}
有人可以向我解释我做错了什么,以及我将来如何解决这个错误?
答案 0 :(得分:3)
List.Add
采用单个参数,但在这种情况下,您传递两个参数,这会导致异常。
同样dataBound: function (e) {
this.enable(false);
}
的类型为sList
,因此您需要的是
MH_ScriptManager
答案 1 :(得分:2)
因为Add
方法应该有一个参数,但你给它两个参数,所以
sList.Add("start", "You awaken in a sweltering room);
更改为:
sList.Add("You awaken in a sweltering room)