Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm struggling to get this working, am I thinking about this wrong!

A)The enemy gets hit by a bullet, stops his walking, plays the animation, start the timer

^^^^^^^^^^^^^^^^^^^^^^^
This all happens but the Enemy is always in his animation loop.



B) If the timer = 0 , play walk animation, put move speed back to 1

any help would greatly be appreciated!

What I have tried:

C#
private float electrickcuted = 2.0f;



if (other.gameObject.CompareTag("bullet")) 
       
       {
          
    SkelAnim.state.SetAnimation(0,electrick,true);
    
    moveScript.WalkSpeed = 0f;

    TakeDamgeEnemy (15f);

    electrickcuted -= Time.deltaTime;
      
        }
    
 if (electrickcuted <= 0.0f)
    
    {

    SkelAnim.state.SetAnimation(0,walk,true);
    
    moveScript.WalkSpeed = 1f;

        }
    }

}
Posted
Updated 1-Feb-19 1:35am
v2
Comments
Member 14135033 1-Feb-19 4:24am    
Thank you @RickZeeland
CHill60 1-Feb-19 4:37am    
Have you debugged this to follow what is happening? How big is Time.deltaTime? Because if it is bigger than the value of electrickuted you drop into the second if block and restart the animation
Member 14135033 1-Feb-19 7:36am    
I managed to solve it by using booleans.

1 solution

C#
private void ElectrickAttack()
{
      if(electrickcuted < 0f)
      {
            Electrickcuted = false;

            SkelAnim.state.SetAnimation(0,walk,true);
     
            moveScript.WalkSpeed = 1f;   

            electrickcuted = 2f;

      }
      else
      {
            electrickcuted -= Time.deltaTime;
      }
}
 
Share this answer
 
v2
Comments
CHill60 1-Feb-19 8:04am    
I personally dislike relying on capitals to determine the difference between Electrickcuted and electrickcuted. This is one of those occasions where including the type in the name would be useful e.g. bElectrickcuted and fElectrickcuted
You've actually solved the problem by inverting the if-statement - you're not using your new Boolean at all. I'm also intrigued where you are declaring all of these variables - I'm hoping they are private properties of the class.
And just because I'm pedantic .. it's spelled "electrocuted" :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900