Answer the question
In order to leave comments, you need to log in
Why do sprites disappear if I change the color with a script?
Here I have a circle consisting of 24 fragments, I painted 1 fragment with my hands, everything is fine, there is a color There
is a script on the fragment like this
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
public class Fragment : MonoBehaviour
{
public FragmentColor ElementColor;
private Circle _circle;
private SpriteRenderer _sprite;
private void Awake()
{
Circle circle = GetComponentInParent<Circle>();
if (circle == null)
{
Debug.LogError("Fragment parent must have a Circle script");
}
else
{
_circle = circle;
}
_sprite = GetComponent<SpriteRenderer>();
}
private void Start()
{
Color color = _circle.GetColor(ElementColor);
_sprite.color = color;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question