function resp (){
if (distance<0);{
var para = document.createElement("p");
var node = document.createTextNode("Yes");
para.appendChild(node);
var element = document.getElementById("inda");
element.appendChild(para);}
else{
var para = document.createElement("p");
var node = document.createTextNode("No, time left:");
para.appendChild(node);
var element = document.getElementById("inda");
element.appendChild(para);}
}
为什么会给我错误:声明或声明预期
答案 0 :(得分:0)
{
direction = Vector2.zero;
if (Input.GetKey(KeyCode.W))
{
direction += Vector2.up;
animator.SetBool("isRunning", true);
}
else if (Input.GetKey(KeyCode.A))
{
direction += Vector2.left;
animator.SetBool("isRunning", true);
}
else if (Input.GetKey(KeyCode.S))
{
direction += Vector2.down;
animator.SetBool("isRunning", true);
}
else if (Input.GetKey(KeyCode.D))
{
direction += Vector2.right;
animator.SetBool("isRunning", true);
}
else
{
animator.SetBool("isRunning", false);
}
}
->
if (distance<0);{
如果您具有诸如webstorm或Visual Studio代码之类的想法,则更容易发现此类问题。
您的代码采用精美印刷的形式:
if (distance<0) {
少量重构后的代码:
function resp() {
if (distance < 0) {
var para = document.createElement("p");
var node = document.createTextNode("Yes");
para.appendChild(node);
var element = document.getElementById("inda");
element.appendChild(para);
} else {
var para = document.createElement("p");
var node = document.createTextNode("No, time left:");
para.appendChild(node);
var element = document.getElementById("inda");
element.appendChild(para);
}
}