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 gamezdragon · Mar 24, 2013 at 11:05 PM · animationrun

Using multiple buttons in script

Hi, I have a script called "Actions" that looks like this:

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 if (Input.GetAxis("Vertical")){
 animation.CrossFade("Walk_");
 }
 
 else if (Input.GetAxis("Horizontal")){
 animation.CrossFade("Walk_");
 }
 
 else if (Input.GetButton("Scratch")){
 animation.CrossFade("Slash");
 }
 
 else if (Input.GetButton("Bite")){
 animation.CrossFade("Bite");
 }
 
 else if (Input.GetButton("Swat")){
 animation.CrossFade("Wing_Swat");
 }
 
 else
 animation.CrossFade("Rest");
 }

I have also added a Third Person Controller Script. I had to put the walk animations and idle animation into my "Actions" script so that the action script wouldn't stop those animations from playing. Now, my question is, how would I add a run animation into my script so that that animation wouldn't be overrode as well?

The Actions Script seems to stop the animations in the Third Person Controller script except for the idle animation. The way I have coped with this is by those same animations into the Actions script. It has worked fine, but with a run animation I would need to be able to press the 'shift' key and the forward key at the same time to run.

How would I script the usage of two keys at once in my actions script for the run animation?

If this is confusing, ask me to explain more clearly.

Thanks!

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

3 Replies

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

Answer by ExTheSea · Mar 25, 2013 at 12:23 AM

I don't know if i quite understood your problem but does this work for you:

     function Update () {
      ...
         else if (Input.GetAxis("Vertical")){
           if(Input.GetAxis("Vertical")>0 && Input.GetButton("Run")){
             animation.CrossFade("Run_");
           }else
             animation.CrossFade("Walk_");
         }
     ....
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 ExTheSea · Mar 25, 2013 at 09:36 PM 0
Share

Btw. If your problem is solved accept and answer or close the question if not please provide more information.

avatar image
0

Answer by goldkillerv · Mar 25, 2013 at 10:17 PM

Why are the buttons named, Bite and Scratch? You probably need to provide us with more information.

Comment
Add comment · Show 3 · 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 ExTheSea · Mar 25, 2013 at 10:21 PM 0
Share

The Bite and scratch thing i guess are just input configuration he did in the input settings. I think bite and scratch aren't even really relevant for this question

avatar image goldkillerv · Mar 26, 2013 at 07:07 PM 0
Share

Ik that he will be able to sprint both ways... It depends on him whether or not he wants to do it or not. He can easily remove it if he doesn't require it. And btw, that's with the holding down shift too which is probably what he wants.

avatar image ExTheSea · Mar 26, 2013 at 09:36 PM 0
Share

Yes right. I'm a bit curious why gamezdragon didn't accepted a question or even just posted a comment if something isn't working or doesn'T fulfill his needs.

avatar image
0

Answer by goldkillerv · Mar 25, 2013 at 10:36 PM

Ok. I think you should try this:

 function Update() {
     
       if (Input.GetButtonDown("Sprint") && (Input.GetButtonDown("Vertical") || Input.GetButtonDown("Horizontal"))) {
     
           animation.CrossFade("Run_");
     }
 }
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 ExTheSea · Mar 25, 2013 at 11:32 PM 0
Share

The Problem with your script is that this way the player will be able to sprint even when walking backwards and sideways. ($$anonymous$$y answer should work for the question. just saying)

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

12 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

Related Questions

play animation when moving,and idle animation when stand still 1 Answer

scripting Animations 1 Answer

Enemy Animation Freezing in first frame 2 Answers

Animay play in editor 0 Answers

how to get a animation from other script on colision 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