C# Unity无法隐式转换类型“0”;“字符串”;至;“bool”;
所以,我正在尝试创建一个测验,这可能是了解我最困难的方式,而这个错误不断出现(线程标题)。这是密码,有人知道怎么了吗C# Unity无法隐式转换类型“0”;“字符串”;至;“bool”;,c#,ios,C#,Ios,所以,我正在尝试创建一个测验,这可能是了解我最困难的方式,而这个错误不断出现(线程标题)。这是密码,有人知道怎么了吗 using UnityEngine; using System.Collections; public class score : MonoBehaviour { public string final_score; // Use this for initialization void Start () { } // Update is called once per
using UnityEngine;
using System.Collections;
public class score : MonoBehaviour {
public string final_score;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (final_score = ("10"))
{
Application.LoadLevel("Result1");
}
if (final_score = ("20"))
{
Application.LoadLevel("Result2");
}
if (final_score = ("30"))
{
Application.LoadLevel("Result3");
}
if (final_score = ("40"))
{
Application.LoadLevel("Result4");
}
if (final_score = ("50"))
{
Application.LoadLevel("Result5");
}
if (final_score = ("60"))
{
Application.LoadLevel("Result6");
}
}
}
这是我的主要问题,但如果可能的话,有人知道unity中测验应用程序的好教程吗?我现在正在使用基本的东西来创建它,但我觉得有一种更简单的方法来实现它,我不知道那是什么。我找到了一些教程,但没有一本是我需要的。我的测验有8个问题,每个问题有4个答案。我需要将每个答案相加,以确定最终结果,共有6个答案。我正在为每个问题/结果使用一个场景,我是否应该更改该场景?但是如果我这样做了,我如何才能正确地获得问题/答案?我整个测验的主要问题是结果。我如何通过不同的场景将问题加起来,以确定结果?谢谢这个项目是在一个时间表上,需要在明天完成,所以快速的结果将是伟大的!请确保修复/教程在iOS和其他移动设备上运行 是赋值运算符,需要使用相等运算符
你的
行和其他行按如下方式执行
- 将
分配给您的“10”
变量最终分数
- 返回此字符串对象
string
和bool
类型之间没有隐式对话,所以会出现此错误。是赋值运算符,需要使用相等运算符
你的
行和其他行按如下方式执行
- 将
分配给您的“10”
变量最终分数
- 返回此字符串对象
由于if语句是expect,并且在
字符串
和bool
类型之间没有隐式对话,所以会出现此错误。以这种方式将代码更新为=
,因为=
运算符是赋值
void Update () {
if (final_score == ("10"))
{
Application.LoadLevel("Result1");
}
if (final_score == ("20"))
{
Application.LoadLevel("Result2");
}
if (final_score == ("30"))
{
Application.LoadLevel("Result3");
}
if (final_score == ("40"))
{
Application.LoadLevel("Result4");
}
if (final_score ==("50"))
{
Application.LoadLevel("Result5");
}
if (final_score == ("60"))
{
Application.LoadLevel("Result6");
}
}
用这种方式将您的代码
=
更新为=
,因为=
操作符是赋值
void Update () {
if (final_score == ("10"))
{
Application.LoadLevel("Result1");
}
if (final_score == ("20"))
{
Application.LoadLevel("Result2");
}
if (final_score == ("30"))
{
Application.LoadLevel("Result3");
}
if (final_score == ("40"))
{
Application.LoadLevel("Result4");
}
if (final_score ==("50"))
{
Application.LoadLevel("Result5");
}
if (final_score == ("60"))
{
Application.LoadLevel("Result6");
}
}
除了比较运算符错误之外,分数似乎应该是一个整数 您还可以通过使用字典或类似的数据结构来避免if语句
Dictionary<int, string> quiz =
new Dictionary<int, string>()
{
{ 10, "Result1" },
{ 20, "Result2" },
{ 30, "Result3" },
{ 40, "Result4" },
{ 50, "Result5" },
{ 60, "Result6" }
};
void Update (int score) {
Application.LoadLevel(quiz[score]);
}
字典测验=
新字典()
{
{10,“Result1”},
{20,“Result2”},
{30,“Result3”},
{40,“结果4”},
{50,“结果5”},
{60,“结果6”}
};
无效更新(整数分数){
应用程序。加载级别(测验[分数]);
}
除了比较运算符错误之外,分数似乎应该是一个整数 您还可以通过使用字典或类似的数据结构来避免if语句
Dictionary<int, string> quiz =
new Dictionary<int, string>()
{
{ 10, "Result1" },
{ 20, "Result2" },
{ 30, "Result3" },
{ 40, "Result4" },
{ 50, "Result5" },
{ 60, "Result6" }
};
void Update (int score) {
Application.LoadLevel(quiz[score]);
}
字典测验=
新字典()
{
{10,“Result1”},
{20,“Result2”},
{30,“Result3”},
{40,“结果4”},
{50,“结果5”},
{60,“结果6”}
};
无效更新(整数分数){
应用程序。加载级别(测验[分数]);
}
在if语句中使用“==”而不是“=”,在if语句中使用“==”而不是“=”,谢谢!我想我忘了那部分了。仍然在寻找第二个问题的答案!谢谢我想我忘了那部分了。仍然在寻找第二个问题的答案@NuckG您需要使用System.Collections.Generic添加
当然,至于你的第二个问题一点也不清楚,也许你可以编辑你的帖子,问1个不多的问题,谢谢。为此,我将提出另一个问题,对此进行进一步解释。@NuckG您需要使用System.Collections.Generic添加当然,至于你的第二个问题一点也不清楚,也许你可以编辑你的帖子,问1个不多的问题,谢谢。我将提出另一个问题,对此做进一步解释。