#pragma strict
var targetscript : Diamond;
var yellow : Color(1,0.92,0.016,1);
var cyan : Color(0,1,1,1);
var green : Color(0,1,0,1);
var red : Color(1,0,0,1);
var magenta : Color(1,0,1,1);
var black : Color(0,0,0,1);
function Start () {
gameObject.camera.backgroundColor = yellow;
}
function Update () {
if (targetscript.score > 4) {
gameObject.camera.backgroundColor = Color.Lerp(yellow, cyan);
}
if (targetscript.score > 9) {
gameObject.camera.backgroundColor = Color.Lerp(cyan, green);
}
if (targetscript.score > 14) {
gameObject.camera.backgroundColor = Color.Lerp(green, red);
}
if (targetscript.score > 19) {
gameObject.camera.backgroundColor = Color.Lerp(red, magenta);
}
if (targetscript.score > 24) {
gameObject.camera.backgroundColor = Color.Lerp(magenta);
}
}
它给了我这些错误:
Assets/Scripts/colour.js(4,22): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/colour.js(4,22): BCE0044: expecting EOF, found '0.92'.
Assets/Scripts/colour.js(4,21): BCE0044: expecting ), found ','.
Assets/Scripts/colour.js(4,19): UCE0001: ';' expected. Insert a semicolon at the end.
我没有发现任何丢失的分号!我没有发现颜色有什么问题!为什么它会给我这么多错误?我检查了脚本超过5次,但我没有发现任何错误!有没有人有任何想法?提前致谢
答案 0 :(得分:1)
由于您正在对一个类进行变量声明,我认为每个颜色声明都需要看起来类似于:
var yellow = new Color(1,0.92,0.016,1);
这会创建一个带有Color类型的黄色变量,然后我们创建一个新的实例并将其指定为黄色。
答案 1 :(得分:0)
var xxx: yyy = zzz;
这是在Unityscript中声明变量的方式,其中xxx是变量的名称,yyy是变量的类型,zzz是值。
在您的情况下,您想要定义一个类型,但是您定义了一个值,因此出现了错误。
将所有内容更改为:
var yellow : Color;
var cyan : Color;
var green : Color;
var red : Color;
var magenta : Color;
var black : Color;
然后在Start()
函数中,给它们值:
yellow = Color(1,0.92,0.016,1);
cyan = Color(0,1,1,1);
green = Color(0,1,0,1);
red = Color(1,0,0,1);
magenta = Color(1,0,1,1);
black = Color(0,0,0,1);
答案 2 :(得分:0)
#pragma strict
var targetscript : Diamond;
var yellow : Color = Color(1,0.92,0.016,1);
var cyan : Color = Color(0,1,1,1);
var green : Color = Color(0,1,0,1);
var red : Color = Color(1,0,0,1);
var magenta : Color = Color(1,0,1,1);
var black : Color = Color(0,0,0,1);
function Start () {
gameObject.camera.backgroundColor = yellow;
}
function Update () {
if (targetscript.score > 4) {
gameObject.camera.backgroundColor = Color.Lerp(yellow, cyan);
}
if (targetscript.score > 9) {
gameObject.camera.backgroundColor = Color.Lerp(cyan, green);
}
if (targetscript.score > 14) {
gameObject.camera.backgroundColor = Color.Lerp(green, red);
}
if (targetscript.score > 19) {
gameObject.camera.backgroundColor = Color.Lerp(red, magenta);
}
if (targetscript.score > 24) {
gameObject.camera.backgroundColor = Color.Lerp(magenta);
}
}