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 roybj · Apr 28, 2014 at 03:49 AM · animationanimator

How can I use parameters value in the animation

Hi,

  1. I am trying to create an animation for a shield charge - that will set the transparency to the charge level gradually. the charge level is obviously not constant. the ugly way as I see it is writing a lot of logic in Update, but I would really like to refrain that. I tried using parameters but I can only use them as conditions not during the animation itself. how should this be implemented?

  2. I tried putting some part of the animation (the shield has a few parts) that is not parameterized into the Animation and the other into Update, but I figured they not both work, is that right?

Thanks, Roy.

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

1 Reply

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

Answer by SteelArrow21 · Apr 28, 2014 at 05:01 AM

In this case, you dont want to use animations. You want to lerp the alpha value like this:

 //C#
 using UnityEngine;
 using System.Collections;
 
 public class ShieldCharge : MonoBehaviour {
 
     public float speed = 1.0f;
 
     void Awake(){
 
         GameObject.renderer.material.color.a = Mathf.Lerp(0.0, 1.0, Time.deltaTime * speed);
 
     }
 }

Make a C# script called "ShieldCharge" and put it in the shield. When the script is activated, it will "charge" the shield.

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 roybj · Apr 28, 2014 at 05:49 PM 0
Share

Thank you very much, Just another thing, lets say I want to all sorts of shield animations and not necessarily on activating it (lets say lerp the transparency according its power by lerping, lerping the color to show a hit animation etc) all together. So I will implement this in the Update function, but the logic and code can become very clumsy.

what is the best strategy for it? (can I use yield for this to make the code simpler? something else?)

Thanks again.

avatar image Dracorat · Apr 28, 2014 at 05:50 PM 0
Share

Please don't post comments as answers. I moved your post to a comment - where it belongs.

avatar image roybj · Apr 28, 2014 at 09:05 PM 0
Share

sorry, my bad. to the point, I wanted to update on what I ended up doing: for all the "logic driven" animation, I removed everything from Update and ins$$anonymous$$d I used coroutines where relevant. for example, In the DamageShield() function I did the following:

 public int DamageShield(int damage)
     {
         StartCoroutine(UpdateShieldActivatedAnimation());
         //DO STUFF HERE
     
     }
 
     private IEnumerator UpdateFullShieldActivatedAnimation()
     {
         for (float r = 1.0f; r > 0.0; r -= Time.deltaTime * FULL_CHARGE_SHIELD_ACTIVATED_SPEED)
         {
             shieldColor.r = r;
             spriteRenderer.color = shieldColor;
             yield return null;
         }
         for (float r = 0.0f; r < 1.0; r += Time.deltaTime * FULL_CHARGE_SHIELD_ACTIVATED_SPEED)
         {
             shieldColor.r = r;
             spriteRenderer.color = shieldColor;
             yield return null; 
         }
         shieldColor.r = 1.0f;
         fullShieldActivated = false;
     }


I guess the UpdateFullShieldActivatedAnimation code can be refactored, but the basic idea is solid. Thanks for the help!

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

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

Related Questions

2D Animation does not start 1 Answer

How to stop mesh disappearing during Animator state transition blend time? 1 Answer

How to synchronize animation in Unity4.x 0 Answers

How can I change my AnimatorState instantly? 1 Answer

how to find out how many seconds into and animation that is playing 2 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