Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by legomastermiles · Mar 19, 2013 at 05:49 AM · animationplayan

how to play an animation by pressing a key

when ever i try to put an animation in the inspector This is what i have.

1.)var PowerOn : Animation; 2.) 3.)function Start () { 4.) 5.)} 6.) 7.)function Update(){ 8.) if(Input.GetKeyDown(KeyCode.F)){ 9.) this.animation.Play("Power On"); 10.) } 11.)}

in the inspecter this is what it shows:

Turn On Power(Script) Script jsTurnPowerOn Power On none(Animation)

when ever i bring the animation i have, or any other animation, and drag it on top it wont let me it has the circle with the line through it how do i make it so i can add an animation.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chronos-L · Mar 19, 2013 at 05:59 AM

 var PowerOn : AnimationClip;
 
 function Start() {
 
 }
 
 function Update() {
    if( Input.GetKeyDown(KeyCode.F) ) {
       animation.Play(PowerOn);
    }
 }

  1. You should use AnimationClip instead of Animation

  2. this.animation is redundant, just use animation

  3. animation.Play("PowerOn") will play the PowerOn animation included in the gameObject, not the PowerOn animation you assign in the inspector. Use animation.Play( animationClipVariable) instead of animation.Play("animationStringName")

Last but not least, use the

 101 
 010

button on the top to format your code, it should be the fifth button from left.

Comment
Add comment · Show 1 · 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 Chronos-L · Mar 19, 2013 at 06:04 AM 0
Share

One more thing, even though PowerOn is technically a okay way to name variables, the better way to do it is powerOn. You can differentiate the name in your script very quickly:

 Class
 Class.StaticFunction()
 variable
 variableWithLongerNames
 variable.Function()
 variable.FunctionWithLongerName()

Function and class should be fully capitalized, while variable should be using a camel style: capitalize all but the first word

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

11 People are following this question.

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

Related Questions

texture "animation" sync with character problem [PAID] 0 Answers

Play animation in child model 0 Answers

Play a video on clicking on an object 1 Answer

On collision play animation 1 Answer

How to make player attack animation play through without holding down a key. 0 Answers


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