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 /
avatar image
0
Question by SGilley_ · Jan 07, 2014 at 09:28 PM · c#animationloopwalking

How do I fix this broken walking animation start in C#?

Hello all, Here is an extremely basic C# script that I wrote to test out a walking animation. I will go back later in the project and hopefully add booleans to control it so I can add jumping animations and the like. I have the walking animation all done. It is attached to the pistol model, and to make sure I dragged the animation to the pistol as well. I then dragged this script to it. I click play and it just plays the animation over and over no matter what I do. I just want some light shed on what I am doing wrong. Thanks.

  using UnityEngine;
  using System.Collections;
         
         
         
  public class walkinanimationpistol : MonoBehaviour {
         
  void Update () {
     if (Input.GetKeyDown ("w")) {
             animation.Play("NameOfWalkingAnim");
     } else {
             animation.Stop("NameOfWalkingAnim");
     }
   }
 }
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 Polymo · Jan 09, 2014 at 07:01 AM 0
Share

from that code i cant see a problem. But you wrote, that you dragged the animation onto the pistol. Is that intended? I would think that it had to be on the character. Because if you reference the character animation component with your "animation", but the actual clip is not in its list, it will only play (if ticked "play automatically") the default animation.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sath · Jan 09, 2014 at 07:45 AM

you are in Update so pushing "w" start animation but in a frame because your are stopping the animation with if else so make it like this

 public class walkinanimationpistol : MonoBehaviour {
 
     void Update () {
         if (Input.GetKeyDown ("w")) {
 //            animation.Play("NameOfWalkingAnim");
             print("play");
         } else if (Input.GetKeyDown ("s")){
 //            animation.Stop("NameOfWalkingAnim");
             print("stop");
         }
     }
 }
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 Polymo · Jan 09, 2014 at 08:01 AM 0
Share

but in his case the animation was looping even though it should have instantly stopped. If it wasn't the problem this would be his corrected code:

 if (Input.Get$$anonymous$$ey("w")){
  //play
 }else{
 //stop
 }
avatar image sath · Jan 09, 2014 at 08:35 AM 0
Share

@ValooFX

else{ //stop }

means that if "w" is not pressed animation stopping all time but if "w" if pressed it is true only one frame after that, keeping it pressed it means nothing READ

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I stop my animation from looping while I hold down a key? 1 Answer

loop animation through controller for period of time? C# 1 Answer

How can i make this animation play only once? C# 1 Answer

How to play animation once in Input.GetMouseButton 1 Answer

Multiple Cars not working 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