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
1
Question by jpizano · Jun 12, 2017 at 06:34 AM · animationscripting problemfps

How do I transition between different animations?

I'm creating an FPS melee combat system (in which both arms are visible). I have created two attack animations along with an idle animation. The idle animation is specific to the left arm, therefore the right arm does not move during the idle animation. However, during the attack animations both arms move simultaneously. I have created a C# script that will play the animations when a certain key is pressed,but I came across a problem. In the beginning of the game the idle animation is playing on the left arm (like it's supposed to), however, when I play the attack animation on the right arm, the left arm stops playing the idle animation all together. I have been trying different ways to fix this but nothing seems to work. Is there a way that can cross fade between the animations? PLEASE HELPalt text

here is the script I created :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ArmAnims : MonoBehaviour {
 
     void Start ()
     {
         GetComponent<Animation>().Play("Idle_Left_Arm");
     }
 
     void Attack1()
     {
         GetComponent<Animation>().Play("Attack1_Right_Arm");
     }    
     
     void Attack2()
     {
         GetComponent<Animation>().Play("Attack2_Right_Arm");
     }
     
     void Update()
     {
         if (Input.GetButtonDown("Fire1"))
         {
             Attack1();
         }
         if (Input.GetButtonDown("Fire2"))
         {
             Attack2();
         }
     }
 
 }
 


2017-06-09.png (274.8 kB)
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

Answer by tMahon · Jun 12, 2017 at 06:41 AM

Use the transitions tool in the Animator state machine. When you get input from the player in code change a Bool in your Animator component like isAttacking1, and set a transition to Attack1 with the condition isAttacking1 = true in the editor. If you need to do more from there you can attach a script to the State object and access OnStateEnter() and OnStateExit().

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 tMahon · Jun 12, 2017 at 06:42 AM 0
Share

The Animator Bools are setup as Parameters in the Animator window

avatar image
0

Answer by MadDevil · Jun 12, 2017 at 06:43 AM

Rather then using the script to change between 2 animation, try making and animation controller and assigning necessary value to have the transition between the 2 animations.

https://unity3d.com/learn/tutorials/topics/animation/animator-controller

check out the above link to see how to use the animation controller.

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

Animations interupting Aim-Script 0 Answers

trying to link an aniamtion in one script to a action in another 0 Answers

Error CS0103, The name GetComponet does not exist in the current context. 1 Answer

Is there a new retargetting system for the animation in 5.5? 1 Answer

How can I use IK with AnimationClipPlayable or AnimationMixerPlayable? 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