Hello everyone.
How can I access the Canvas by code?
Supposedly it is like this:
canvas = GetComponent<Canvas>();
But it’s not working. Error: There is no ‘Canvas’ attached to the “NaveJugadorRojo” game object, but a script is trying to access it. You probably need to add a Canvas to the game object “NaveJugadorRojo”. Or your script needs to check if the component is attached before using it.
And also how can I access, for example, a text by code.
I didn’t find anything useful in the documentation or in other forums.
I have to use it and get it by code, since the object that needs it is created during the game and you have to add those components to it. Is there another way to assign the Canvas and other UI elements other than by code?