Forum rules - please read before posting.

Instantiating game objects

I have a canvas panel with some text in my scene, at the bottom of the screen. It is deactivated in the inspector. I want it to be activated when the player clicks on a hotspot. I’ve set up an action Object - add and entered the canvas game object but it does not appear. If it is activated when the scene opens and I use Object - remove it deactivates the Object. I’ve tried entering the Vector 3 details but it still doesn’t work. How can I fix this please?

Comments

  • Object: Add or remove will spawn an instance of a prefab into the scene, but here you're trying to enable a GameObject that's already present - the two operations aren't the same thing.

    You should generally avoid enabling/disabling GameObjects at runtime, since Unity can lose the reference to a disabled GameObject. Better to disable the Canvas component itself instead, and control its enabled state through animation. Attaching an Animator to the Canvas, adding "Canvas on" and "Canvas off" animations to it, and then playing those animations with Object: Animate is one approach.

    However, since you're using Canvases / RectTransforms, it might be better to link the Canvas to a Unity UI Menu in AC's Menu Manager, since you can then control it's enabled state with the Menu: Change state Action. If the Canvas is supposed to appear in multiple scenes, make it a prefab and link it to a Menu whose Source field is set to Unity Ui Prefab. If it's only supposed to be in one scene, leave it in the scene and set the Source to Unity Ui In Scene. See the Manual's "Unity UI Menus" chapter for more on this topic.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.