请问代码错在哪里啊,找不到!?

我用的代码//
var Speed = 50;
//
var Control;
{
//
Control = GetComponent(js1);
//
if(Input.GetKey(KeyCode.W));
{
//
Control.ForWard();
}else if(Input.GetKey(KeyCode.S));
{
//
Control.Back();
}
if(Input.GetKey(KeyCode.A));
{
//
Control.GLeft();
}else if(Input.GetKey(KeyCode.D));
{
//
Control.GRight();
}
if(Input.GetKey(KeyCode.Q));
{
//
Control.leftRotate(Vector3.up *Time.deltaTime * -Speed);
}else if(Input.GetKey(KeyCode.E));
{
//
Control.RightRotate(Vector3.up *Time.deltaTime * Speed);
}
}
错在那里呢?

HUWWW
浏览 132回答 1
1回答

MMMHUHU

要这样写var Speed = 50;//var Control;function Update(){ //要用Update()方法//Control = GetComponent("js1"); //GetComponent()里面填的是字符串类型。//if(Input.GetKey(KeyCode.W)) //if(xxx)后面是没有" ; "的{//Control.ForWard();}else if(Input.GetKey(KeyCode.S)){//Control.Back();}if(Input.GetKey(KeyCode.A)){//Control.GLeft();}else if(Input.GetKey(KeyCode.D)){//Control.GRight();}if(Input.GetKey(KeyCode.Q)){//Control.leftRotate(Vector3.up *Time.deltaTime * -Speed);}else if(Input.GetKey(KeyCode.E)){//Control.RightRotate(Vector3.up *Time.deltaTime * Speed);}}鉴于规范和效率问题,应该是要这样写规范:变量名(var 变量名 : 类型)开头字母小写,方法名(function 方法名(){})开头字母大写。效率:声明变量时应该都定义好变量类型, GetComponent.<js1>();比 GetComponent("js1”);更好var speed : int = 50; //改成小写开头//var control : js1; //改成小写开头,js1这个类名应该也要大写开头才规范function Update(){//control = GetComponent.<js1>();//if(Input.GetKey(KeyCode.W)){//control.ForWard();}else if(Input.GetKey(KeyCode.S)){//control.Back();}if(Input.GetKey(KeyCode.A)){//control.GLeft();}else if(Input.GetKey(KeyCode.D)){//control.GRight();}if(Input.GetKey(KeyCode.Q)){//control.LeftRotate(Vector3.up *Time.deltaTime * -speed); //原来这里的leftRotate我改成大写了,注意一下}else if(Input.GetKey(KeyCode.E)){//control.RightRotate(Vector3.up *Time.deltaTime * speed);}}
打开App,查看更多内容
随时随地看视频慕课网APP