GameObject.SetActive() v.s. GameObject.active
GameObject.SetActive() v.s. GameObject.active
usage:
attribute active of a GameObject checks whether the GameObject is active or not.
method SetActive(bool b) of GameObject is a method that sets the attribute of GameObject active is b.
When you use GameObject.SetActive (false) or GameObject.active=false to deactivate the GameObject, then OnDisable() event will be triggered. After that, the GameObject.active will set to be false and GameObject will be deactive.
When you use GameObject.SetActive(true) or GameObject.active=true to activate the GameObject, then OnEnable() event will be triggered. After that, the GameObject.active will set to be true and GameObject will be active.
I prove it on my script. Unity Version: 2020.3.12f1.590.2 Personal
NOTE:
When the GameObject is deactive, you can NOT acess it and its compoent including its BoxCollider, Script which is attcahed to GameObject and transform etc.
When the GameObject is deactive, the name of GameObject in hierarchy in Unity will be grayed which is not same as the other active GameObject.
source:
more details on
Comments
Post a Comment