I am making a game, and I want to be able to detect a mouse click. I checked the Unity Scripting API, and my code should work. To make sure that it would work, I inserted a debug command. However, when I tested it, I never got a debug message. Did I overlook anything or misspell anything? Also, I am new to forums, so if I mistagged it, or put it in the wrong sub forum, please let me know.
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour {
void Update() {
if (Input.GetMouseButtonDown(0)) {
Debug.Log(“Left Clicked”);
}
}
}
Verify both the script component and the GameObject it is attached to are both enabled in the scene. Add a Debug.Log statement before the “if” statement to verify Update() is even being run.
I did, they are both enabled in the scene. Also, I updated the code to have another if statement. As I said, the void Update does not seem to be called.
Can you show a screenshot of your editor, with this object selected, and the script showing up in the GameObject’s inspector? There must be something simple that is set up wrong. Update() getting called is extremely reliable when set up correctly.
I think the eventsystem is missing.
When you create a new scene unity adds one object called “EventSystem” to your hierachy.
I cant’s see that in your screenshot.
Can you verify your script changes are actually saved? Just click on GameController in the Project window and look at what code it shows in the inspector. Also verify you have not disabled the various message categories in the console.