0

While Instantiating the buttons and adding them to the scene, I need to perform some kind of animations, so they get added to the scene with a slide down animation (or slide left or slide right). My code so far:

for (int i = 0; i < 4; i++) {
        // Instantiate 4 buttons
        Transform clone =  (Transform)Instantiate (suggestionBtn, 
                                               new Vector3 (4, y, 0), Quaternion.identity);
        // make instance the child of the canvas
        clone.SetParent(gameObject.transform, false); 
        clone.transform.rotation = transform.localRotation;
        y -= 70;
}

I am not sure whether I need to make animation files and attach them to each button I need to animate or use some engine like LeanTween or is it just few lines of code that will ensure slide down/ slide left/ slide right animations?

Malloc
  • 15,434
  • 34
  • 105
  • 192
  • All tough this is an old and overly complex script. You might be able to get something use full out of this http://pastebin.com/18Xp09Ai It has the setup for 4 buttons, each having another 4 buttons. Which slide down and after that sidewards. Itween and leantween would also be a good option. – MX D Dec 22 '14 at 16:25
  • If you don't want to use a 3rd party asset (iTween), you can create your own tween method. Look at a similar question here and look at my answer http://stackoverflow.com/questions/27119906/animate-move-translate-tween-image-in-unity-4-6-from-c-sharp-code/27121705#27121705 – Savlon Dec 23 '14 at 08:49

1 Answers1

1

You can use iTween to do this:

static float y0;
static float FadeInOutTime = 1.0f;

//Called in Awake()
y0 = GameObject.Find("button_home").transform.position.y;

public static IEnumerator AnimateIn ()
{
    int i = 0;

    foreach (var item in ToolbarButtons) {
        var pos = item.transform.position;
        iTween.MoveTo(item, new Vector3(pos.x, y0 + 6, pos.z), FadeInOutTime);
        yield return new WaitForSeconds (i * 0.02f);
        i++;
    }
    yield return null;
}

enter image description here

David
  • 15,894
  • 22
  • 55
  • 66