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 Ngoadam123 · Jan 17, 2014 at 02:18 AM · animationbuttonpress

How to make animations on button press.

I am trying to make it so my model does animations on a button press. So w for walking and so on. Can someone guide me to make a script for a var as well? So when I edit the character I can select the animation for the button pressed, like the default third person.

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

2 Replies

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

Answer by FPSworrior · Jan 17, 2014 at 02:28 AM

 //You could put as many of these as you want for more animations
 var animationToPlay1 : String;
 var keyToPress1 : KeyCode;
 var animationToPlay2 : String;
 var keyToPress2 : KeyCode;
 
 
 function Update()
 { 
   if(Input.GetKey(keyToPress1))
   {
     animation.CrossFade(animationToPlay1);
   }
    if(Input.GetKey(keyToPress2))
   {
     animation.CrossFade(animationToPlay2);
   }
 }
Comment
Add comment · Show 13 · 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 Ngoadam123 · Jan 17, 2014 at 04:18 PM 0
Share

Ok this script looks promising, I'm going to try this when I get home. I tried adding on to it if I need more animations, would this work?

 //You could put as many of these as you want for more animations. 1 - Walk 2 - Sprint 3 - Crouch
 var animationToPlay1 : String;
 var keyToPress1 : $$anonymous$$eyCode;
 var animationToPlay2 : String;
 var keyToPress2 : $$anonymous$$eyCode;
 var animationToPlay3 : String;
 var keyToPress3 : $$anonymous$$eyCode;
  
  
 function Update()
 { 
   if(Input.Get$$anonymous$$ey(keyToPress1))
   {
     animation.CrossFade(animationToPlay1);
   }
    if(Input.Get$$anonymous$$ey(keyToPress2))
   {
     animation.CrossFade(animationToPlay2);
   }
    if(Input.Get$$anonymous$$ey(keyToPress3))
   {
     animation.CrossFade(animationToPlay3);
   }
 }
avatar image Ngoadam123 · Jan 17, 2014 at 08:47 PM 0
Share

Also do I add it to the model or player

avatar image Ngoadam123 · Jan 17, 2014 at 08:56 PM 0
Share

I get errors for the keys, I put in left shift and other keys like c. Also I cant use it. It says the compilation isnt done

avatar image FPSworrior · Jan 18, 2014 at 06:01 AM 0
Share

First off, yes you put the script on the player. Also what kind of errors are you getting. Can you put them on here so that I can see them?

avatar image Ngoadam123 · Jan 18, 2014 at 01:50 PM 0
Share

Omg nvm, I'm so dumb XD I fixed it you just keep it blank. Going to try the script now. Thanks!

Show more comments
avatar image
0

Answer by Prasad uchil · Jan 30, 2014 at 11:31 AM

i have an question how can i put a gui texter or gui button it and this script dosent have any gui option so how can i make it i want to use it in android phone and tab so can you help

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 Ngoadam123 · Feb 05, 2014 at 10:19 PM 0
Share

ask your own question

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

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

Related Questions

Button Press and Hold Animations 0 Answers

how to disable a button after pressing it and enable again after pressing another button 1 Answer

Animate object on mouse button press 1 Answer

What am I doing wrong with this attack script? 2 Answers

Animation pause on button press? 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