Search Unity

Bug Editor automatically presses keys after scene started

Discussion in 'Editor & General Support' started by xadd, Jun 25, 2023.

  1. xadd

    xadd

    Joined:
    May 25, 2023
    Posts:
    11
    Hello, so I was recently testing the editor to see if there was a bug regarding automatic key press. I simply added a plane, cube, and a script attached to the cube here:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class keyPressBug : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.    
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         if(Input.GetKeyDown(KeyCode.S));
    17.         {
    18.             Destroy(gameObject);
    19.             print("s pressed");
    20.         }
    21.     }
    22.    
    23. }
    As shown, I want the cube to disappear only when I press the key. However, the cube disappears right after I hit the play button and it prints to let me know that the key was already pressed! How can I resolve this issue?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,705
    xadd likes this.