- Home /
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 :)
To make it clear you want newly spawned enemies to have their default Rotation ins$$anonymous$$d of the transform.Rotate(0,0,90) they have when they die?
Answer by Bunny83 · Dec 09, 2012 at 12:36 AM
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?
Answer by Tibie · Dec 09, 2012 at 09:37 AM
Thanks for your Reply .
your solution worked , :)
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