Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Missing GetComponent<Animation>().Play

Discussion in 'Scripting' started by Pharmi, Apr 28, 2017.

  1. Pharmi

    Pharmi

    Joined:
    Oct 18, 2015
    Posts:
    7
    Hey Community,

    some days ago I was playing around with Unity 5.5 and realised that some functions are missing. I tried to add an animation , nothing special. But Mono develop "told" me, that there is no "Play()" function for GetComponent<Animation>() anymore. I checked the Unity 5.5 API and suprise, the function is still there. Do you know why my Unity version is making fun with me?

    Regards

    Kristian
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    I could be wrong but I believe you would do it this way now;

    Code (CSharp):
    1. anim = GetComponent<Animation>();
    2.  
    3. anim.Play();
     
    Pharmi likes this.
  3. Pharmi

    Pharmi

    Joined:
    Oct 18, 2015
    Posts:
    7
    Thanks WarmedXMints this helps me alot!
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Animation is the old, obsolete animation component. Unless you explicitly set your models to import as "Legacy", Animator is the class you want.