-7
return playerInfo[name][timetype];
线。我不知道什么是错的。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Linq;
using System.Collections.Generic;
// scoreboard
public class bandau : MonoBehaviour
{
Dictionary<string, Dictionary<string, string>> playerInfo;
// Use this for initialization
void Start()
{
SetName("po", "time", "0220");
Debug.Log(GetName("po", "time"));
}
void Init() // to do then its needs to be done
{
if (playerInfo != null)
{
playerInfo = new Dictionary<string, Dictionary<string, string>>();
}
}
public int GetName(string name, string timetype)
{
Init();
if (playerInfo.ContainsKey(name) == false)
{
return 0;
}
if (playerInfo[name].ContainsKey(timetype) == false)
{
return 0;
}
return playerInfo[name][timetype]; //Where is the problem?
} //function to get player name ant other parameters
public void SetName(string name, string timetype, string value)
{
Init();
if(playerInfo.ContainsKey(name) == false)
{
playerInfo[name] = new Dictionary<string, string>();
}
playerInfo[name][timetype] = value;
} // set player values
public void ChangeName(string name, string timetype, string amount)
{
Init();
int currName = GetName(name, timetype);
SetName(name, timetype, currName + amount);
} // if needs to be changed
// Update is called once per frame
void Update()
{
}
}
'GetName'的返回类型是'int'。这听起来应该是'string'。 –
显然'playerInfo [name] [timetype]'是一个字符串,你将它作为整型返回值返回。 –
显然'playerInfo [name] [timetype]'是一个'string'。正如错误告诉你的那样。 – David