1

I've a project in Unity 2018.2.21f1. I have already a C# script for handling coins in my game, called CoinHandler.

It already as a gameobject in the scene, and it has linked some components (text) that it has to update.

enter image description here enter image description here

Then I've a button added to the scene (as you can see in the first picture), and I try to call a function from the previous script in his on click() event. For this, I go to the inspector and drag&drop the coinHandler gameObject, and select the desired function (method, since it returns void).

enter image description here

You may notice that the icon of the gameObject in this picture changes to the script icon. I don't know if this is a bad sign, but just notice it. It changes just after selecting the function. Before, it remains with its proper icon:

enter image description here

And finally, in the console I'm getting the next warning:

No script asset for GameObjectSelectionItem. Check that the definition is in a file of the same name.

Of course, both name of the script and of the class inside it are the same.

I've readed that this may be because of having the animator window open. I had, but I closed it, and everything was the same, fixed nothing.

Any idea about why may be happening?

5
  • Do you have EventSystem in your scene? Commented Apr 23, 2019 at 21:01
  • @Johnny I don't, the only objects that I've are that ones from the first picture in the post! Commented Apr 23, 2019 at 21:04
  • Add one to the root of the scene... Commented Apr 23, 2019 at 21:11
  • Totally! That was it! Any modification that I have to do? Post it as an answer pls Commented Apr 23, 2019 at 21:14
  • No, everything seems fine, that's it. Commented Apr 23, 2019 at 21:15

1 Answer 1

1

If you want to use UI elements, button for example, you need to add EventSystem to the scene. The scene should contain only one EventSystem and it could be anywhere in the hierarchy. Take a look at the official documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.