![Unity Game Object Instance Id Unity Game Object Instance Id](https://answers.unity.com/storage/temp/92127-unity.png)
Fast access to information on a Unity GameObject without having to call GetComponent.
The name of the Unity GameObject to perform the callback method on. The string contains the user id, username, and gameauthtoken of the current. Example: A MonoBehaviour that initializes the API, ensures only one instance will be. Dec 31, 2015 How to use the GetComponent function in C# with Unity 3D to access and manipulate a game object's components through C# code. My latest Udemy course teaches beginners how to.
FastLookup.cs
usingUnityEngine; |
publicclassFastLookup : MonoBehaviour |
{ |
[SerializeField] |
publicstaticintLookupListSize=547; //!< Size of static data arrays. Prime numbers are best, in theory. |
publicconstuintFlagAllocated=1<<0; //!< This index has been reserved for use. |
publicuintIdx; //!< Per-instance index into the static data arrays. |
//! Convert an instance id to a FastLookup Index. |
//! |
//! @param instanceId Unity Object instance id, obtained via Object.GetInstanceID() |
//! |
//! @return A unique index into the FastLookup static data arrays. |
publicstaticuintInstanceIdToIndex(intinstanceId) |
{ |
return (uint)instanceId% (uint)Flags.Length; |
} |
#regionData Arrays |
publicstaticuint[] Flags; |
publicstaticVector3[] LastPosition; |
#endregion |
#regionMonoBehavior Stuff |
voidStart() |
{ |
if(Flagsnull) |
{ |
Flags=newuint[LookupListSize]; |
LastPosition=newVector3[LookupListSize]; |
} |
Idx=InstanceIdToIndex(gameObject.GetInstanceID()); |
// If we're debugging, put in some extra checks |
#ifUNITY_EDITOR |
if((Flags[Idx] &FlagAllocated) FlagAllocated) |
{ |
Debug.Log('InstanceId collision detected! Consider increasing lookup list size.'); |
Debug.Break(); |
} |
#endif |
Flags[Idx] =FlagAllocated; |
} |
voidOnDestroy() |
{ |
Flags[Idx] =0; |
} |
#endregion |
} |
![Get object by name unity Get object by name unity](http://i.stack.imgur.com/3aecI.png)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment