Prefab object not responding to being clicked

I have a bunch of prefabs instantiated, each with this script attached:

using UnityEngine;
using System.Collections;

public class NodeData : MonoBehaviour {
	
	    public int nodeIndex;
        public string nodeName;
        public int    nodeNumIP;
        public string nodeCountryCode;
        public float nodeLatitude;
        public float nodeLongitude;   
        
        private bool showData = false;

        void OnMouseDown()
        {
        	showData = true;
        	Debug.Log("True");
        	
        	int waitSeconds = 5;
        	
        	StartCoroutine(WaitSomeTime(waitSeconds));
        	
        	showData = false;
        	Debug.Log("False");	        	
        }     
        
        IEnumerator WaitSomeTime(int waitTime)
        {
        	yield return new WaitForSeconds(waitTime);
        }
        
        void OnGUI()
        {
        	if(showData) {
        		Debug.Log("Clicked!");
        		GUI.Label (new Rect (10, 10, 100, 20), "Clicked!");
        	}
        }
}

When I move the camera so one of the nodes is clearly visible, and then put the mouse pointer over the node and left click, none of the Debug.Log statements show up, nor does the GUI.Label.

I’m clearly missing something here but haven’t been able to figure out what. Help, please? :face_with_spiral_eyes:

Thanks in advance!

[quote]
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.

This function is not called on objects that belong to Ignore Raycast layer.
[/quote]Did you add a Collider to your prefab?

Okay, that was simple. I did, but then I forgot I removed it when I was fighting with that run time error. Just put it back and of course it responds now.

There’s a new problem though: it’s supposed to wait five seconds and then change back to false, but it’s flipping instantly back without waiting. Is there something wrong with my wait coroutine?

Okay, I think I figured it out. I put the switch back to false here, instead:

        void OnMouseDown()
        {
        	showData = true;
        	Debug.Log("True");
        	
        	int waitSeconds = 15;
        	
        	StartCoroutine(WaitSomeTime(waitSeconds));
        	
        	// showData = false;
        	// Debug.Log("False");	        	
        }     
        
        IEnumerator WaitSomeTime(int waitTime)
        {
        	yield return new WaitForSeconds(waitTime);
        	showData = false;
        	Debug.Log("False");	        	
        }

That seems to work. I guess I didn’t understand where the wait actually happens, before.

Thanks!