Can anyone help me why this code is not working!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update
    (
        if (Input.GetKeyDown(KeyCode.Space))
        (
            Debug.Log("Space key was pressed down");
        )
    )





    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
  // Start is called before the first frame update
  void Start()
  {

  }
  // Update is called once per frame
  void Update()
  {
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Debug.Log("Space key was pressed down");
    }
  }
}

Edit: also you were missing () at the end of Update - added.

Surely the compiler is telling you… but you’re using parentheses ( and ) to open and close your method and if-statement scopes when you should be using curly brackets { and }.

ALso you have an extra closing curly bracket on line 27.

1 Like

Let me try this and I will see how it goes!

It works! Thanks!

1 Like