How To Call Animation where need to call?

by jishan nuran   Last Updated August 13, 2019 13:13 PM

I Create 35 Level and 35 Animation??

Because of My Each, Level Obstacle Position is Different Some Level Have 10 obstacle and Some Level Have 15 Obstacle So I Create an Each level different animation.

ex

  • Level1 animation is different (level1anim) I put this animation on obstacle game object and name is level1anim
  • Level2 animation is different (level2anim) I put this animation on obstacle game object and name is level2anim
  • Level3 animation is different (level3anim) I put this animation on obstacle game object and name is level3anim
  • Level4 animation is different (level4anim) I put this animation on obstacle game object and name is level4anim

Obstacle.cs // I Have Only One script

    void OnTriggerEnter2D(Collider2D other)
     {
             foreach (Transform child in transform)                          
             {
                if (child.tag == "obstacleobject" || child.tag == "movefastobject") 
                {
//when player touch my obstacle then i want to play animation(But i have 35 animation and 35 level ex(Level1->animlevelone,Level2->animleveltwo)      
//each level different animation

                      //i want to call animation here Because My Player collide with obstacle 
                      //ex Level1(player collided with obstacle)->call the animation level 1->Level1animation.Play("leveloneanim"); 
                      //ex Level2(player collided with obstacle)->call the animation level 2->Level2animation.Play("leveltwoanim"); 
                      //ex Level3(player collided with obstacle)->call the animation level 3->Level3animation.Play("levelthreeanim"); 
                }
     }

PlayerManager.Cs //here i store my level

public string currentscenename;

public string nextscenename;

   void GoNextLevel()         //Level store script
   {
         int num = PlayerPrefs.GetInt("Level", 0);             
         Debug.Log("Num1:" + num);
         num++;
         PlayerPrefs.SetInt("Level", num);

         if (currentscenename == nextscenename)       
         {
             GoNextLevel();
             Debug.Log("InsideIf");
         }
         else
         {
             SceneManager.LoadScene(nextscenename);  
             Debug.Log("INSIDE ELSE");
         }
    }

I Have No Idea Which Concept Used?? can give any suggestion??

Tags : unity 2d animator


Related Questions


Updated July 19, 2016 08:05 AM

Updated February 17, 2019 22:13 PM

Updated February 28, 2019 06:13 AM

Updated November 24, 2017 01:13 AM

Updated December 26, 2018 07:13 AM