方法`CharacterSave'没有重载需要`1'参数

时间:2017-08-17 08:58:04

标签: c# unity3d

当我将项目升级到最新的Unity版本时出现此错误..

不知道我错了哪一部分。但这是我的代码片段

CharacterModule.cs

var prefab = Instantiate(characterData).GetComponent<Player>();
prefab.name = characterName;
prefab.account = user.Username;
prefab.className = request.ClassName;
prefab.transform.position = gameConfig.startPosition;
prefab.health = prefab.healthMax;
prefab.mana = prefab.manaMax;
Database.CharacterSave(prefab);
Destroy(prefab.gameObject);

var gameUser = GameUserModule.Database.Get(user.Username);
if (gameUser == null)
{

GameMapnetwork.cs

        // add to client
    NetworkServer.AddPlayerForConnection(connection, go, 0);
}

public void SaveCharacters()
{
    if (!NetworkServer.active)
        return;

    Database.CharacterSaveMany(Player.onlinePlayers.Values.ToList());
}

public void SaveCharacter(Player player)
{
    Database.CharacterSave(player);
}

GameModule.cs

var go = Database.CharacterLoad(name, GameConfig.Instance.GetPlayerClasses());
if (go == null)
{
    message.Respond("Character not found", ResponseStatus.Failed);
    return;
}
var player = go.GetComponent<Player>();

var gameUser = gameUserDatabase.Get(user.Username);
if (gameUser == null)
{
    gameUser = GameUserModule.Database.CreateObject(user.Username);
    gameUserDatabase.Insert(gameUser);
}
gameUser.SelectedCharacter = name;
gameUserDatabase.Update(gameUser);

string resultMap = player.savedCurrentMap;
Vector3 resultPosition = player.transform.position;

if (string.IsNullOrEmpty(resultMap))
{
    resultMap = player.savedCurrentMap = GameConfig.Instance.startScene;
    resultPosition = player.transform.position = GameConfig.Instance.startPosition;
    Database.CharacterSave(player);
}

Destroy(player.gameObject);

if (mapCallback != null)
    mapCallback(resultMap, resultPosition);

这是我的一些代码。我不知道哪个部分是错的。我真的很感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

基本上你提到的错误告诉你,你没有在参数列表中定义一个名为CharacterSave的方法,其中只有一个参数。类似的东西:

CharacterSave(paramType paramName)

您应该向我们展示您实施该方法的位置:

CharacterSave(...)

也可能只是使用重载方法SaveCharacters:

混合名称
SaveCharacters()
SaveCharacter(Player player)