Which gameObject should I attach my Chronometer script to ?

Hello, I am trying to implement a simple chronometer feature in order to complete a Tutorial. What I struggle with is manipulation of the TimeText Object. When I attach the Chronometer Script to the Canvas, and then drag the TimeText, I cannot drop it into the public Text variable. I don’t understand what should be done in order to show time running down in the scene. I would like help about this issue please.

From your screenshot you have the inspector of the script itself open. You need to open the inspector for the GameObject you attached to script to in the scene (if you attached it to the Canvas object, then that one). From the hierarchy window. Then you can drag objects into the Time Text slot there.

1 Like

With Unity you can pretty much attach scripts to any GameObject. What matters is anything in the script which already assumes it will be attached to a certain GameObject (such as when you use gameObject.GetComponent<>() to get a reference to another component on the same GameObject), and your planned life cycle for the GameObject. Also, usually you want to attach scripts to some logical place, so you can easily find it months later.

I attached the Chronometer script to the Canvas, but I cannot drop the TimeText gameObject into the public Time Text variable. I don’t understand.7430684--909965--Unity Chronometer Problem 2.jpg

SOLVED ! The solution is to use A Text UI instead of a TextMeshPro UI. Now I can drag the TimeText gameObject into the public TimeText variable.