Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Score, Enemies, and Game State Manage the Game State

Ranvir Sahota
Ranvir Sahota
9,844 Points

Don't understand Behviour.enables

Can someone explain this documentation to me Enabled Behaviours are Updated, disabled Behaviours are not.

This is shown as the small checkbox in the inspector of the behavior. https://docs.unity3d.com/ScriptReference/Behaviour.html

I wanted to understand what varaibleName.enabled=false was doing but I only ended up getting confused. Can someone help.

1 Answer

Alan Mattanó
PLUS
Alan Mattanó
Courses Plus Student 12,188 Points

Refers to the image of the new UI. [enalble or disable the image] Make a canvas UI. Then in it , create a new UI -> image. Now add the script is in the example. To the script add a public bool OnOff; to turn on and off or to hide the image. Surround pauseMenu.enabled = true; with an if statement. Save the script and return to Unity. If you try to drag and drop an image or a sprite into the component it do not work. But if you click next to the fileld "PouseMenu" there is a round button. if you click in it a new window will pop up and now you can select the item. The item must be a game object containing a Image script components. In this example will be itself because we didn't create other UI Image game objects. but if you create other Ui Image, you can drag and drop that one. Return to the script and add

   else
    {
        pauseMenu.enabled = false;
    }

Drag and drop an image sprite to the Image Script to the variable Source Image.

Start the game: Now if OnOff is enable at start, then the image will be there in the game. Now if OnOff is not enable the image will be not there in the game.

This is better that enable or disable the game object when there are script running as component in the game object you want to hide an image.

.