Starting Animation from random time frame Unity

Code snippet to start the animation at different time. Useful when there are many same animation running on screen and you want to make them random.

Animator anim = GetComponent<Animator> ();
AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo (0);
anim.Play (state.fullPathHash, -1, Random.Range(0f,1f));

You can add this code in Start or Awake function and add to the GameObject with the Animator component.

C# code to shuffle Array

private T[] ShuffleArray<T>(T[] array) {
    System.Random r = new System.Random ();
    for(int i = array.Length; i > 0; i--) {
        int j = r.Next (i);
        T k = array [j];
        array [j] = array [i - 1];
        array [i - 1] = k;
    }

    return array;
}

Example:

Int Array

int[] intArray = new int[] {1,2,3,4};

intArray = ShuffleArray(intArray);

Float Array

float[] floatArray = new float[] {1.0f,2.0f,3.0f,4.0f};

floatArray = ShuffleArray(floatArray);

Touch In Order – Windows 8.1 App

Finally i have Windows 8.1 app in the Windows app store. I build this app with the help of my friend. We have developed a number game to click the numbers in regular order during Windows 8.1 DevCamp. MIC Nepal had organized Windows 8.1 App DevCamp. This App is written in Visual C#. This app was selected as one of the best app in that DevCamp.

The numbers are in random order and there is a time limit for you to complete the Challenge.

touch-in-order
Touch In Order – Visit the App page.

Update (10 June, 2014): I have developed similar game for Android. You can get it in Google Play Store Touch in Order.