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 camtronius · May 30, 2014 at 03:52 AM · colorrtsfixedupdatetime.deltatimeattack

How to reset attack animations using time.deltatime

Hi everyone, I am in the process of making two units fight each other in an RTS. I was writing some code and trying to use Time.deltaTime but I noticed that it continuously updates time so it wont trigger my code. I am looking for alternatives that would produce the same effect. I am looking to have the units attack duration to take 1 seconds, and in that 1 second to change its color then reset so I know it has animated. I have provided my code below. Thank you,

 public void FixedUpdate(){

     if (enemyAttacking == true) {
         if(atkCounter<atkDuration){
             renderer.material.color = new Color32(255, blueColor, 255, 1);
             atkCounter +=Time.deltaTime;
             blueColor-=1;
             print (atkCounter);
         }
     
     if(atkCounter>=atkDuration){
         Debug.Log ("-----------------------the enemy hit a player unit!");//simple test for enemy attack
         atkCounter=0;
         blueColor=255;
     }
 }


 }
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 2dfruity · May 30, 2014 at 12:45 PM

i use a cooldown and Time.time. because if time always increases, and if you add to it when storing into another var you can compare it to Time.time and have an "attack rate"

 if (Time.time >= coolDown){
                     GoulAttack();
                     coolDown = Time.time + attackRate;
                 }
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
avatar image
0

Answer by wijesijp · May 30, 2014 at 05:02 AM

I think the best way to do this is to add a trigger to the end of your attack animation. That way you don't have to do much in FixedUpdate.

Set the trigger to call a function like this...

 public void AnimationCompleted(int animID)
 {
      blueColor = 255;
 }

 public void FixedUpdate()
 {

     if (enemyAttacking == true)
     {
         renderer.material.color = new Color32(255, blueColor, 255, 1);
         blueColor -= Time.deltaTime;

     }

 }
Comment
Add comment · Show 2 · 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 camtronius · May 30, 2014 at 05:29 AM 0
Share

@wijesijp I appreciate your comment, but i do not have an attach anim yet. I was using the color change as a placeholder for attack anim. I saw another tutorial use timer.deltatime to control his anims and reset them using what I used above. Is there any way to have this way work? Thanks!

avatar image wijesijp · May 30, 2014 at 10:27 AM 0
Share

There are few things you can check

1) Since you are in FixedUpdate you must use Time.fixedDeltaTime

2) I think the problem line may be this blueColor-=1;

It should be blueColor -= Time.fixedDeltaTime;

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

Changing two different objects renderer colour 1 Answer

Different game speed 2 Answers

Get actual Time.deltaTime from FixedUpdate() 0 Answers

RTS faction color 0 Answers

Does Time.deltaTime not work in FixedUpdate? 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