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 Dreave · Nov 28, 2011 at 04:26 PM · animation

Animation Scripting Help

I have an animation script for my walk and idle animation, I also have an animation for my shoot and reload (all scripts are at the bottom). But I have this problem that if I have both scripts attached to my gun the animations clash and dont work properly. I haven't done anything to the animation options on the gun inside the inspector window which I think I need to do, can anyone help me with this?

walk and idle script;

 function Start(){

 

   animation["walk"].speed = 1;

   

   animation["idle"].speed = 0.5;

   

   animation.wrapMode = WrapMode.Loop;

 

}

function Update () {

if (Input.GetAxis("Vertical") > 0.2)

    animation.CrossFade ("walk");

else

   animation.CrossFade ("idle");

}

shoot script;

 function Start () {



animation["shoot"].speed = 2;

}

function Update () {

if(Input.GetButtonDown("Fire1")){

animation.Play("shoot");

}

}

reload script;

function Start () {

animation["reload"].speed = 1;

}

function Update () {

if(Input.GetButtonDown("r")){

animation.Play("reload");

}

}

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
1
Best Answer

Answer by TheEmeralDreamer · Nov 28, 2011 at 10:33 PM

Try setting each animation to an appropriate layer.
For instance if you have a ready animation for your character, you will want that animation to run all the time in a loop, however, you will also need attack animations and being struck by enemies,etc , to play.
So if you set the attack animations to play once and set them to a higher level, they will get priority, and once they are done playing, the ready animation will resume.

For the above code I believe you would need to set idle animation to layer 1. Then the walk animation to layer 2. The walk animation would need to be set to PingPong, whilst the idle animation would be set to loop.

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 jahroy · Nov 28, 2011 at 10:50 PM 1
Share

Nice. Thanks for answering this and finally explaining to me what these mystical animation layers are.

I've seen no less than a half-dozen questions just like this one since I started playing with animations last week.

The documentation is very clear that playing an animation stops all other animations in the same layer. Now I know what that means!

avatar image TheEmeralDreamer · Nov 29, 2011 at 06:47 AM 0
Share

no problem!

avatar image Dreave · Nov 30, 2011 at 08:10 AM 0
Share

Thanks for your help

avatar image
0

Answer by jahroy · Nov 28, 2011 at 10:27 PM

I recommend reading the documentation for the functions you're using.

When you call Animation.Play or Animation.CrossFade, it effects all the animations that are currently playing (on the same layer).

I am very new to animations, but a quick scan of the documentation suggests that the animations triggered by your code will constantly interrupt each other.

The code that you've shared will cause the idle animation to play every frame that the up button is not being pressed. Otherwise, the walk animation will play.

If you want your shoot and reload animations to play, you probably have to stop your walk/idle animation (and vice versa).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Trying to simply play this animation... Help please. 1 Answer

Reacting to Mouse animation... 2 Answers

Loop animation on button hold 2 Answers

How could it be done "Cooldown" for a shield ? 2 Answers

play animation sequence 3 Answers


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