input key is always pressed

  • i tried with all the keys and don´t stop
    • using System.Collections;
  • using System.Collections.Generic;
  • using UnityEngine;
    • public class Porta1A2 : MonoBehaviour
  • {
  • public bool open;
  • public GameObject rotate;
    • void Start()
  • {
  • open = false;
  • }
      • void Update()
  • {
  • if (Input.GetKey(KeyCode.F));
  • {
  • Debug.Log(“presss”);
  • open = true;
    • }
  • if (open == true)
  • {
    • transform.localRotation = Quaternion.Lerp(transform.localRotation, rotate.transform.localRotation, 2);
  • }
  • }
    • }

It is not that the key is always pressed, it is because as soon as you press the F key, you set the variable open to be true. Nowhere do you set it to be false, so if (open == true) will always run as it is always true when the Update method runs.

You need to determine where you want it to be switched to false (I would guess straight after the transform.localRotation ... line and put open = false; there.

Please look up how Lerp works and why 2 is a nonsense parameter to use. Your current code equivalent to this: transform.localRotation = rotate.transform.localRotation.

well i fixed it removing the semicolons after the if, but now i can´t use esc key XD the key it´s not broke in my keyboard but it´s not woking in unity…

if (Input.GetKeyDown(KeyCode.Escape))
{
MenuEsc = true;
}
if(MenuEsc == false)
{
onibus.GetComponent().enabled = true;
escMenu.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.Escape))
{
MenuEsc = false;
}
if(MenuEsc == true)
{
onibus.GetComponent().enabled = false;
escMenu.SetActive(true);

Got the same problem that my character is moving automaticly. I tryed a lot of character controll variations but my “s” input is always pressed so the chaacter moves backwards automaticly. I dont know what to do cause nobody has this bug. I downloaded app that shows my input and it doesnt show that my “s” key is pressed so idk. If anyone can help please reply

Please post your code with code tags.