Click here to Skip to main content
15,883,831 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have struggled with this for so long now, I have tried so many things.

in the police script! if his health reaches 0, then his box collider is disabled

in the enemy script, I have that if he hits police collider ATTACK ( WORKING FINE)

else if police collider is disabled then WALK! (NOT WORKING)

Any help would really help me pass the locked door.

What I have tried:

<pre lang="c#">

void OnTriggerEnter2D (Collider2D other)            
     {
         
         if(other.gameObject.CompareTag("policeFootCol")) 
         { 
          moveScript.WalkSpeed = 0f;
          SkelAnim.state.SetAnimation(0,attack,true); 
          
         }    
         else if (PoliceScript.FootStopperPolice.activeSelf == false)
         {
         moveScript.WalkSpeed = 1f;
         SkelAnim.state.SetAnimation(0,walk,true);     
         }
Posted
Updated 14-Feb-19 11:59am

Based on your description:

The "if" test on "PoliceScript" for active should be in the "if" for the "collider" (police) ... (active vs not active "police" collider).

You should have a "switch" if dealing with multiple colliders to keep one's head straight.
 
Share this answer
 
Comments
Member 14135033 15-Feb-19 6:20am    
Sorry, Gerry! I have been trying again for hours today and since your message last night. In the police Script, at the start method, his collider is active true when his health is 0; collider active false, This is like a switch right? on and off. In the enemy script, if he collides with police then fight else walk, the problem still remains when the police health is 0 and collider is switched off! then enemy is still in attack mode
Solved in the update method I put.


if (state == State.ATTACKING && currentTarget && !currentTarget.activeSelf)
        {
        walking();
        }
 
Share this answer
 

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