How to keep a Gameobject in the same position after a transform.Rotate?

Hey everyone , I recenlty made an enemy in my unity game , he has a health bar etc.
and when his health reaches 0 , i want him to tip over.~
(using c# btw)
so here is what i used :

public Gameobject Enemy2;

void Update()
{
    if(CurrenHealth == 0)
    {
        Enemy2.transform.Rotate(0,0,90);
    }
}

when i use it this way , the enemy starts spamming from his default position , to this rotated position , prpably because the if statement is called again every frame , so it keeps doing it?

Does anybody know how i can Keep the Enemy in this new position?

Thanks :slight_smile:

Sure, just stop rotating him. The easiest fix is to disable the script:

0

Hey everyone , I recenlty made an enemy in my unity game , he has a health bar etc. and when his health reaches 0 , i want him to tip over.~ (using c# btw) so here is what i used :

public Gameobject Enemy2;

void Update()
{
    if(CurrenHealth == 0)
    {
        Enemy2.transform.Rotate(0,0,90);
        enabled = false;
    }
}

However i’m a bit confused. When the script is attached to your enemy, why do you rotate another object?

Thanks for your Reply .

your solution worked , :slight_smile:

And where you said “However i’m a bit confused. When the script is attached to your enemy, why do you rotate another object?”

Hehe your right , i removed the Gameobject and it works just the same ;p

Thanks for the Help