Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Rinku · Dec 23, 2015 at 02:10 PM · animationunity 5javascript

How to access Animation using java script & attach it to the object ?

i have created the walking & idle animation for my fps player. i've added a java_script to access it. but, when i run it & press button(w), it stops & says that, the animation is not attached to the object.. when i drag the walking/idle animation & drop to that object, it creates an animation controller. again i run it, still same error. i can't find where to attach the animation ?????? thnx for help... @Adamcbrz @Olgo @whydoidoit @VildNinja @hollym16 @ Here's my java script:

function Update () {

     if(Input.GetKeyDown("w"))
     {
         GetComponent.<Animation>().Play("walk_anim2", PlayMode.StopAll);
     }
     if(Input.GetKeyUp("w"))
     {
         GetComponent.<Animation>().Play("idle_anim2", PlayMode.StopAll);
     }

     

}

Comment
Add comment · Show 10
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 Rinku · Dec 22, 2015 at 10:25 PM 0
Share

@hexagonius Hlp pls !!!

avatar image hexagonius Rinku · Dec 22, 2015 at 10:37 PM 0
Share

are you sure its Animation and not Animator?

avatar image ShadyProductions · Jan 04, 2016 at 05:56 PM 0
Share

GetComponent<Animation>() or GetComponent<Animator>()

avatar image vintar ShadyProductions · Jan 04, 2016 at 05:58 PM 0
Share

Is that not C# ? the OP did say JavaScript

avatar image ShadyProductions vintar · Jan 04, 2016 at 06:10 PM 0
Share

Javascript isn't my default choice :P, I think they work in both cases otherwise it should be;

GetComponent(Animation) or GetComponent(Animator)

Show more comments
avatar image Rinku · Jan 05, 2016 at 11:46 AM 0
Share

Nope, it's on the correct object. @vintar anyway, actually i want to acces the walk animation for my FPS when a particular key is pressed. so, can u tell me a simple step by step procedure ? ? ? newbies here !!!
@hexagonius

avatar image Rinku · Jan 05, 2016 at 02:32 PM 0
Share

alt text

game.jpg (151.5 kB)
avatar image Rinku Rinku · Jan 04, 2016 at 05:44 PM 0
Share

i've added the screenshot.

i had once added the animation component too. but, that was also not working. anyway, what exactly i have to do right now? @hexagonius

avatar image allenallenallen Rinku · Jan 05, 2016 at 02:33 PM 0
Share

Use comment and not answer when you don't have an answer!!! Converted to comment.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Jan 06, 2016 at 07:28 AM

first, it is GetComponent(Animator)

second, it works like a state machine with transitions where you define the conditions in those white arrows. In your case this would be a speed float value higher than 0 for entering walking and 0 for going back to idle. the animator uses SetFloat for this.

see the docs for a description of the Animator about how to use this and read this carefully to get an understanding how everything works

http://docs.unity3d.com/Manual/AnimatorControllers.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with attacking, and death animation. Unity 5 javascript 1 Answer

How to loop unity?JS 3 Answers

Animation Played when key pressed Help 1 Answer

Animation depending on the Int value 0 Answers

Horizontal axis not working after animation 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