2D Game Problem

Updated on July 29, 2017 in  [G] Say Hello!
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on July 29, 2017

Is there any way I can make this code that I’m using check twice if space bar was pressed.

 

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Space)) print("space key was pressed"); } }
  • Liked by
Reply
0 on July 29, 2017

You can also use the GetKeyUp() to see if it was released, like so:

private void Update()
 {
      if(Input.GetKeyDown(KeyCode.Space))
      {
             Debug.Log("space key pressed");
      }
 
 
      if (Input.GetKeyUp(KeyCode.Space))
      {
            Debug.Log("space key released");
      }
}

 

Not sure if that meets your requirements or not. Let me know if it does, and I can suggest another method if needed. 

Cheers,

-J

  • Liked by
Reply
Cancel