Unity3d game development How to hide objects

Source: Internet
Author: User
Tags api manual

hidden objects only need to call Gameobject's SetActive method,


gameobject.setactive (FALSE);//Hide
gameobject.setactive (TRUE);//Display

but occasionally there is a case that can not be shown again after the hidden, because the developer has gameobject into a local variable, the developer let every time the operation of the control to go to the current find, but the Find method can only find to setActive true object, Fin D This function only returns the active Game object, so it cannot find the control after it is hidden and cannot be displayed again. "Dog Planing Learning Net"

that's one of the mistakes I've made, and I used to like it, but the API manual says:
For performance reasons it was recommended to does use this function every frame Instead cache the result in a member VA Riable at startup or use Gameobject.findwithtag.
It is not recommended to use this function in each frame unless it is a necessity. You can use a member variable to cache the result at the beginning, or the Gameobject.findwithtag function.
so try not to get into the bad habit of using the current tune every time.

WORKAROUND: Simply set the Gameobject as a global variable, find it once in awake (or a suitable location as needed), and go directly to the reference elsewhere without having to do a find operation again.

a beginner, just want to put their own solution to the problem to write up, save a backup, you can also help other beginners.
Perhaps the problem is too simple, I hope the great God do not spray, there are mistakes also please point out, thank you very much.

Unity3d game development How to hide objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.