S
S
stasersmailov2021-07-19 17:19:04
Unity
stasersmailov, 2021-07-19 17:19:04

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

60f5894a7d593985838072.jpeg
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;
    }
}

After I start the games, the fragment with the script just disappears, but the color changes correctly, the object itself is in the same place and the sprite has not changed
60f589c091967958427426.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-07-19
@stasersmailov

You have transparency at zero, so you can't see anything. As always , no one provides
the necessary code , because they think that the error is probably in the banal assignment of values._circle.GetColor(ElementColor)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question