Disable Key using C#
i want to disable a key after it has been pressed. but i dont know how. i only want it to be pressed once and reset when i reset the scene. heres my code in C#:`using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems;
public class Score : MonoBehaviour {
Text text;
public int multiplier = 5;
public GameObject player;
public GameObject hoppkant;
float beginpos;
float endpos;
private bool landing = true;
private bool totalDistance;
public LayerMask Distance;
public Transform groundCheckPoint;
public float groundCheckRadius;
void Start()
{
text = GetComponent<Text>();
beginpos = hoppkant.transform.position.x;
}
private void Update()
{
landing = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, Distance);
if (landing && Input.GetKeyDown(KeyCode.DownArrow))
{
endpos = player.transform.position.x - beginpos;
int distance = Mathf.RoundToInt(endpos * multiplier);
text.text = "Distance: " + distance + "m";
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Checking if any key is up? 3 Answers
Continuous force after keypress? 0 Answers
How can i do an action after i detect a collision2D && and a key/mouse button being pressed? 1 Answer
How to use a key as trigger? 2 Answers
Boomerang weapon? 0 Answers