- Home /
Why wont my sprite renderer show when enabled?
I have multiple GameObjects running the same script, each object has a tag that I'm using to reference them individually. I may be misusing this function. For whatever reason when I choose to enable individual sprite renderers it shows in the editor inspector as enabled with the checkmark, but in fact, it does NOT render either in the scene window or the game window. When running in the editor if I click to enable the sprite renderer component it does render and the inspector reflects this correctly. The console window also shows each element showing the correct values.
For the example given I am only trying to make the first circle sprite render.
Here I have the setup for the renderer:
void Start()
{
m_SpriteRenderer = this.GetComponent<SpriteRenderer>();
m_SpriteRenderer.enabled = true;
}
Here is my function for enabling and disabling sprites:
void ActiveCircles ()
{
//first circle
if (m_gameManager.circles == 0)
{
if (this.tag == "C2" || this.tag == "C3")
{
this.m_SpriteRenderer.enabled = false;
}
else if (this.tag == "C1")
{
this.m_SpriteRenderer.enabled = true;
}
}
//second circle
else if (m_gameManager.circles == 1)
{
if (this.tag == "C1" || this.tag == "C3")
{
this.m_SpriteRenderer.enabled = false;
}
else
this.m_SpriteRenderer.enabled = true;
}
//third circle
else if (m_gameManager.circles == 2)
{
if (this.tag == "C1" || this.tag == "C2")
{
this.m_SpriteRenderer.enabled = false;
}
else
this.m_SpriteRenderer.enabled = true;
}
else
this.m_SpriteRenderer.enabled = true;
}
Here is my Update Function:
void Update ()
{
//this.colour = bsBlack.btnVal;
ActiveCircles();
switch( this.tag )
{
case "C1":
Debug.Log(this.tag);
ColourShift();
Debug.Log("C1 Sprite =" + this.m_SpriteRenderer.enabled);
break;
case "C2":
ColourShift();
Debug.Log(this.tag);
Debug.Log("C2 Sprite =" + this.m_SpriteRenderer.enabled);
break;
case "C3":
ColourShift();
Debug.Log(this.tag);
Debug.Log("C3 Sprite =" + this.m_SpriteRenderer.enabled);
break;
}
}
Here is before I click on the
SpriteRenderer
check box while running:
Here is after I click on the
SpriteRenderer
check box while running:
Do you have more than one Sprite Renderers on the same GameObject? If yes, that might be the issue. In that case, move one of the Sprite Renderers into a child GameObject of that GameObject and reference the Sprite Renderer from that child