- Home /
How can I flip only my 'Player' gameobject, and l leave it's child object alone?
I have a Player gameobject and it has a child gamobject attached to it, the Player gameobject has a script attached to it which basically flips the Player, but it also flips the Player's child gameobject. How Can I Make The Player's Child GameObject Not Flip, While The Player Still Flips While Moving Left Or Right
Here's My Script:
private void Flip(float horizontal)
{
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 thescale = transform.localScale;
thescale.x *= -1;
transform.localScale = thescale;
}
}
Answer by Timo326 · Sep 24, 2017 at 09:21 PM
An easy solution would be to flip the child(ren) too after or before the parent has flipped.
@$$anonymous$$326 Can you explain and show some c# scripting examples of how I will do this.
private void FlipChildren() // untested
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).localScale *= -1;
}
}
Answer by MaxGuernseyIII · Sep 24, 2017 at 09:27 PM
@Timo326's answer is valid. Were it me, I would make the two objects that you want to flip independently siblings inside a larger GameObject. Then I would make the larger game object the thing that moves around (thus moving both children at the same time) but I would only flip the Player game object.
Your answer
Follow this Question
Related Questions
Don't Flip Child, Only Parent. 0 Answers
Flip Player, but don't flip the Player's Child. 2 Answers
Add audio. 1 Answer
How to Find gameObject child. 3 Answers
What happened to Line Renderer! 1 Answer