I have an empty game object that has children but when I GetComponentInChildren(); it gets component only from the first child, how to make it to flip the sprite together with all of the children.
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpriteFlipper : MonoBehaviour
{
SpriteRenderer sr;
private void Awake()
{
sr = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") < 0)
{
if (sr != null)
{
sr.flipX = true;
}
}
if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") > 0)
{
sr.flipX = false;
}
}
}
,I have an empty game object that has children but when I GetComponentInChildren(); it gets component only from the first child how to make it to flip the sprite together with all of the children
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpriteFlipper : MonoBehaviour
{
SpriteRenderer sr;
private void Awake()
{
sr = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") < 0)
{
if (sr != null)
{
sr.flipX = true;
}
}
if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") > 0)
{
sr.flipX = false;
}
}
}