- Home /
SpriteRenderer is gone when I change in script.
So, I had an idea for making a game that include characters customization, and I want to make user can actually change the character's body color. But, I have a problem in here. When I drag the sprite that I want to render, it is just gone. This is the picture of it :
][2]][1]][1]
Here is how the spriteRenderer object looks like :
But in the gameplay, the body doesn't show up, it's just the other sprite that showed up!
This is the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class skinColor : MonoBehaviour {
public GameObject panel;
public SpriteRenderer body;
public Color[] colors;
public int whatColor = 1;
void Update()
{
for(int i=0; i<colors.Length; i++)
{
if(i == whatColor)
{
body.color = colors[i];
}
}
}
public void ChangePanelState(bool state)
{
panel.SetActive(state);
}
public void ChangeBodyColor(int index)
{
whatColor = index;
}
}
[2]: /storage/temp/125502-capture.png
Answer by GenericToast · Oct 02, 2018 at 11:53 PM
The alpha values of your colors are set to 0, so your sprite is there but it is totally transparent so you won't be able to see it. Just change your alpha value of your colors to something higher using the inspector for your sprite to show up.
Your answer
Follow this Question
Related Questions
WebGL sprite appears pink? 0 Answers
Translucent sprites appear solid 0 Answers
Unity Game View won't refresh my sprites 1 Answer
How to change spriterenderer to everyone with RPC 0 Answers
2 Animation Clips, 1 Sprite 0 Answers