GameObject
class GameObject : Object
Description
GameObject is a scene intractable object.
GameObject's can represent players, shapes and scenery. In more easy way, GameObject is set of components, to add for that object real functionality.
Properties
Inherited Properties
name
Name
of this GameObject.
Constructors
GameObject
Create new GameObject and attach Transform component.
GameObject(string name)
Create new GameObject with name
and Transform.
GameObject(string name, params string[] components)
Create new GameObject and attach array of components
by name
.
GameObject(params string[] components)
Create new GameObject and attach array of components
by name
.
GameObject(string name, params Type[] components)
Create new GameObject and attach array of components
by type.
GameObject(params Type[] components)
Create new GameObject and attach array of components
by type.
Static Methods
CreateGameObject
Create a copy of GameObject with the same components.
If you want modify object components data and that was affected on runtime scene throw script code use MonoScript.CreateGameObject(other).
CreateGameObject(PrimitiveType primitiveType)
Compares two gameobjects.
Compare
Create new GameObject and attach array of components
by name
.
Destroy
Destroyes Component or GameObject or Asset. If Component, GameObject, Asset is null this method does nothing.
If obj is type of GameObject it will be destoryed after OnUpdate()
loop is finished. If object attached to MonoScript, object calls OnDestroy()
method to free all user resources, detach object from script and remove all components. If GameObject is null this method does nothing.
If obj is type of Component then immediately detach Component from assisated instance of GameObject. If component is MonoScript,
object calls OnDestroy()
method-event to free all user resources. If Component is null this method does nothing.
If obj is type of Asset (Texture2D, AudioClip, Font, etc) it immidiatly removes it if possible.
Methods
CompareTag
Has the game object input tag
?
CompareName
Has the game object input name
?
Compare
Compares two components.
AddComponent
Adds new component to this GameObject, and return this
component.
AddComponent<T>
[Generic Version]
Adds new component with type T
to this GameObject, and return this
component.
AddComponent(Type componentType)
[Type Version]
Adds new component with Type
to this GameObject, and return this
component.
HasComponent
[Type Version]
Returns true
if given component attached to this GameObject otherwise false
. Use this if you want fastest performance because it just recall native function.
HasComponent<T>
[Generic Version]
Returns true
if component atleast has one attached component of given type T
to this GameObject otherwise false
.
HasComponent(string componentType)
[String Version]
Returns component of given type
from this component GameObject, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject.
GetComponent
[Type Version]
Returns the given component of the given type
if it attached to this GameObject. This method will return the first component with this type that he found.
GetComponent(string componentType)
[String version]
Returns the given component if it attached to this GameObject.
GetComponent<T>
[Generic Version]
Returns the given component of type T
if it attached to this GameObject. If component not exist then this return null
instance.
GetOrAddComponent
[Type Version]
Returns component of given type
from this component GameObject, it component exist t component not exist, will add new component of given type to this GameObject.
GetOrAddComponent<T>
[Generic Version]
Returns component of T
from this component GameObject, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject.
GetOrAddComponent(string componentType)
[String Version]
Returns component of given type
from this component GameObject, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject.
GetComponents
Return the array with all given components in GameObject.
TryGetComponent(Type componentType, out Component component)
[Type Version]
Tries to retrive the component of given type
from component GameObject. This method will returns true
and output not-null component if it exist. If component was not found, this returns false
and set output component to null
.
TryGetComponent<T>(out Component component)
[Generic Version]
Tries to retrive the component of given type T
from component GameObject. This method will returns true
and output not-null component if it exist. If component was not found, this returns false
and set output component to null
.
TryGetComponent(string componentType)
[String Version]
Tries to retrive the component of given type
from component GameObject. This method will returns true
and output not-null component if it exist. If component was not found, this returns false
and set output component to null
.
GetUUID
Returns the Unique ID of this GameObject.
SetActiveInScene
Sets the object active state
in scene. If object is active that it will rendered and perfom any physics behaviour on it.
SetActiveInEditor
Sets the object active state
in editor. If object is active in editor it can be visualized in editor if not it will be hidden.
IsActiveInScene
Returns true
if object is active in scene.
IsActiveInEditor
Returns true
of object is active in editor.
ToString
The string
representation of GameObject.
Inherited Methods
GetObjectID
Returns the ID
of current object. ID
is unique only per one runtime session. Each sessions of runtime/play mode will change the ID
of object. Not recommend equal object by ID
if this not one runtime session.
See Also
Last updated