- Home /
c# List not fully clearing
Is there any reason a List won't fully empty despite being given specific commands? I have an if statement which reads:
if (myTransform.position.y <= -12.8f)
{
//ballState = BallState.RestingBall;
GameManager.CalculateScore(ballColor);
//create a popper in the lane where it went through
Instantiate(Popper, new Vector3(myTransform.position.x, -10f, myTransform.position.z), Quaternion.identity);
Instantiate(PopperBloom, new Vector3(myTransform.position.x, -10f, myTransform.position.z), Quaternion.identity);
BallList.Remove(this);
Destroy(gameObject);
}
I'm finding that it works for various balls going off the bottom of the screen but for some reason the List count won't go below 1, even though all the balls disappear from the hierarchy panel in Unity. I'm keeping track of the number of balls with a simple GameManager.numBallsInList = BallList.Count; statement at the top of my Ball.Update() method. Is there a c#/Unity reason for this happening or is it me doing something wrong?
@simesf: You will have to provide us some more information or code, because this seems fine. removing it from your ballList is ok. Have you tried debugging with $$anonymous$$onoDevelop? http://unity3d.com/support/documentation/$$anonymous$$anual/Debugger.html
Also, make sure you're not adding the same object to the list multiple times.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Voting System Using List (C#) 1 Answer