Hi, I got a script that instantiates a prefab each 20 seconds, and that prefab is supposed to choose a random sprite for itself and another for its child.
The thing is that it is getting his sprite with its random color but his child doesn’t even get its random sprite.
Both have a SpriteRenderer component attached and the parent has the script too, here is my code if someone can help me:
using UnityEngine;
public class BGTemplate : MonoBehaviour
{
public Sprite[] upperPart;
public Sprite[] bottomPart;
private SpriteRenderer upperRenderer;
private SpriteRenderer bottomRenderer;
private float speed = 0.25f;
(float, float, float, float) upperColor;
(float, float, float, float) bottomColor;
// Start is called before the first frame update
void Awake()
{
bottomRenderer = GetComponent<SpriteRenderer>();
upperRenderer = GetComponentInChildren<SpriteRenderer>(true);
}
private void Start()
{
int randomSprite = Random.Range(0, upperPart.Length);
bottomRenderer.sprite = bottomPart[randomSprite];
upperRenderer.sprite = upperPart[randomSprite];
upperColor = (Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0.4f, 0.6f));
bottomColor = (Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0.4f, 0.6f));
Color newUpperColor = new Color(upperColor.Item1, upperColor.Item2, upperColor.Item3, upperColor.Item4);
Color newBottomColor = new Color(bottomColor.Item1, bottomColor.Item2, bottomColor.Item3, bottomColor.Item4);
upperRenderer.color = newUpperColor;
bottomRenderer.color = newBottomColor;
}