使用箭头键旋转对象

时间:2015-06-08 15:17:06

标签: unity3d scripting

按下水平箭头键时,我正在尝试旋转对象Cannon。我的C#脚本看起来像这样;但遗憾的是我在Unity中解析错误和“Unexpecting symbol”{'“:(

使用UnityEngine; 使用System.Collections;

public class NewBehaviourScript:MonoBehaviour {

public float HorizontalKeys;
public Transform Cannon;

void Start () {

}

// Update is called once per frame
void Update () {
    if(Input.GetAxis("HorizontalKeys")){
        if(Input.GetAxis ("HorizontalKeys" == -1){
            Cannon.transform.Rotate(Vector3.right * Time.deltaTime);
            Debug.Log("Test");
        }if(Input.GetKey ("HorizontalKeys" == 1){
            Cannon.transform.Rotate(Vector3.left * Time.deltaTime);
            Debug.Log("Test");
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

使用附件")"

完成if语句
if(Input.GetAxis ("HorizontalKeys" == -1)) {

}