Code only executes once.

I am a noob working on a project, and all of a sudden code that would repeat (say clicking on an object) has stopped repeating and only works once. In an effort to rule things out, I finally created a simple project with a cube game object and attached the following code.

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

public class Q : MonoBehaviour
{

void Start()
{

}

void Update()
{
if (Input.GetKeyDown(KeyCode.Q)) 
{
Debug.Log("q has been clicked");
}
}
}

This will only perform once; if I press the key more times, there is no more log read out.

Maybe this is the expected result. Maybe I am imagining the whole thing. I have also tried updating unity editor in case I have broken it, but the same thing happens with the latest release.

Any pointers would be gratefully received.

Can you show the log after you have pressed it multiple times? Verify the GameObject this is attached to is still alive in the scene hierarchy.

I’m guessing you just have “Collapse” toggled on in your console. It hides duplicate log messages.

That was my guess as well, and why I asked for the log :stuck_out_tongue:

1 Like

Dooh! Four days struggling with this, and it was just my clumsy mouse finger. Well, I have learned something new! A million thanks guys! I can start doing stuff again now.

6054278--655091--Captura.JPG