Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SirOrange · Feb 13, 2017 at 12:09 PM · animationanimatoranimate

Animation Not playing

Animation Not playing. why? error CS1061: Type UnityEngine.Component' does not contain a definition for Play' and no extension method Play' of type UnityEngine.Component' could be found. Are you missing an assembly reference?`using System.Collections; using System.Collections.Generic; using UnityEngine;

public class HeadHit : MonoBehaviour {

%|-1814071339_1|% void Start () { %|1205629864_3|% %|1624323751_4|%

%|1732494877_6|% void Update () { if (Input.GetKey(KeyCode.E)) { animation.Play ("Hit0"); %|620421206_10|% %|765253691_11|% %|-1072008687_12|% } %|1153412139_14|% }`

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirOrange · Feb 12, 2017 at 03:49 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class HeadHit : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E)) {
             animation.Play ("Hit0");
         }
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Q)) {
             animation.Play ("Hit1");
         }
     }
 }

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by T_Lavell · Feb 13, 2017 at 07:37 PM

Try explicitly referencing your animator component. Instead of using the shortcut 'animation', try creating an Animation variable, and tell THAT to play. Try...

 public Animation _anim;
 
 void Start ()
 {
     _anim = gameObject.GetComponent<Animation>();
 }
 
 // Update... If (input ... )
     _anim.Play("AnimationNameHere");

I'm not certain this will solve your problem, but it should work. I haven't seen the specific error you've shown before, but it seems not to realize you are trying to reference the legacy animation component.

Also, unless you are working on an old project that is firmly entrenched in the legacy animation system, I would highly recommend switching to the new mecanim animator system. It requires a bit of learning to set up the animator controller transitions, but I find it is really much easier to use once you catch on to that stuff.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirOrange · Feb 13, 2017 at 11:49 PM 0
Share

I have no idea how to set up an animator, do you have some kind of video/tutorial that i can learn from?

avatar image T_Lavell · Feb 14, 2017 at 05:10 AM 0
Share

https://m.youtube.com/watch?v=7RtRiniiW0c

YouTube is your friend

avatar image
0

Answer by OmerDoron · Feb 14, 2017 at 05:52 AM

You want to get the animator that contains those 2 animations, then when desired key is down (don`t use get key, because it will load the animation every frame while holding) tell the animator to play the desired animation. (make sure the strings are exactly the same)

try this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class HeadHit : MonoBehaviour {
 
     public Animator animator; //assign the animator here.
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.E)) {
             animator.Play ("Hit0");
         }
         if (Input.GetKeyDown(KeyCode.Q)) {
             animator.Play ("Hit1");
         }
     }
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by chetan312 · Dec 16, 2020 at 05:42 AM

hello everyone, i know this is very old question , but i had similar problem few days ago. So in my case , i accidentally created a script called "Animator". Now my all animations in project called this script (this script is empty), so as result i got lot of errors . so just look in your project, if you had also an script named as "Animator" which is created by you and delete it because it is conflicting the pre made classes of unity. Sorry for my bad English. Hope this is useful.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation resetting to the muscle pose 0 Answers

How to make a pre-animated model respond to player input? 0 Answers

Animation only runs in prefab and scene, but not during runtime. 1 Answer

Animation constantly resetting? 0 Answers

Animator won't let me add transitions 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges