Using arrow keys to rotate an object

2k views Asked by At

I'm trying to rotate an object Cannon when pressing the horizontal arrow keys. My C# script looks like this; but sadly I get parsing error and "Unexpecting symbol '{'" in Unity :(

using UnityEngine; using 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

There are 1 answers

0
maraaaaaaaa On

Finish your if statements with an enclosing ")"

if(Input.GetAxis ("HorizontalKeys" == -1)) {

}