Reputation: 87
Coding Language: C#
Experience: I know my way around the basics
I am currently trying to make a 2D unity game, and the goal is to break blocks. To achieve this, the sprite uses a "hit point" system, then deletes it's self when it hits zero. BUT, for some odd reason, Unity keeps the sprite loaded in the game view. It is gone in my scene view, so I know it is working. It just won't disappear in my game view. I have tried searching for some sort of refresh for the SpriteRenderer component, but I can't seem to find anything.
private void Start()
{
if (depthMultiplier == 0)
{
hitPoints = 3;
}
}
void OnMouseDown()
{
hitPoints -= 1;
Debug.Log(hitPoints);
if (hitPoints == 0)
{
GameObject.Find("PlayingScreen").GetComponent<Spendables>().gold += 1;
Destroy(gameObject);
}
}
}
Code I am currently using
Sprites go away in scene view, but not game view.
EDIT - Might be worth nothing, I am using an Orthographic camera, and the object is also removed from the hierarchy
Upvotes: 0
Views: 964
Reputation: 87
Ok, fixed my own problem. After messing around with the camera for a little while, I found the Clear Flags property. Apparently, I had just turned this off instead of changing the Skybox.
Upvotes: 0