Skip to main content


Showing posts from February, 2016

How to create unique ID in unity

Hi guys,

Sometime we come in a situation where we need to assign an unique id to our gameObject or any other thing.
Creating a random number is not reliable because there is a chance that 2 generated numbers can be same.
So i came up with a simple solution, in which i am generating a number by mixing date and time of the system, which will never be same, because it changes every micro second.

Here is the function to get Unique ID,

string[]split= System.DateTime.Now.TimeOfDay.ToString().Split(newChar[]{':','.'});

Or you can use  :
'System.Guid.NewGuid()' as suggested by 'Yed' in comments.

If you like this post and want to contribute Please click on the link given below.