Can someone tell me why my list.add is not working. I have been scouring the net and trying to figure this out of hours. If I put the same list.add line in start, It adds the item to the list. Where the line is now, it does not add anything. I have confirmed that the code is running through the constructor correctly, but for some reason when I print the list, there are 0 entries.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScoreCard : MonoBehaviour {
public int FrameIndex = 0;
public int TotalScore = 0;
List<Frames> FrameScore;
private Ball ball;
private PinSetter pinSetter;
void Start()
{
FrameScore = new List<Frames>();
pinSetter = GameObject.Find("PinSetter").GetComponent<PinSetter>();
ball = GameObject.Find("Bowling Ball").GetComponent<Ball>();
}
public void UpdateScore(int BallIndex, int PinStandingCount)
{
switch (BallIndex)
{
case 0:
if (PinStandingCount <= 0)
{
print("Frame: " + FrameIndex + " STRIKE!!!");
Frames TempScore = new Frames(FrameIndex, 10, true);
FrameScore.Add(TempScore);
FrameIndex++;
break;
}
print("Frame: " + FrameIndex + " Score: " + (10 - PinStandingCount));
FrameScore.Add(new Frames(FrameIndex, (10 - PinStandingCount)));
break;
case 1:
break;
case 2:
default:
break;
}
}
public void PrintFrameScores()
{
print("Current Frame: " + FrameIndex);
print(string.Format("Printing {0} Frame Scores", FrameScore.Count));
foreach (Frames frame in FrameScore)
{
print("Frame: " + frame._FrameNum);
print("Ball 1: " + frame._BallScore1);
print("Ball 2: " + frame._BallScore2);
print("Ball 3: " + frame._BallScore3);
print("Bowled Strike: " + frame._BowledStrike);
print("Bowled Spare: " + frame._BowledSpare);
}
}
}
public class Frames
{
public int _FrameNum = 0;
//BallScore contains the score of each ball.
public int _BallScore1 = 0;
public int _BallScore2 = 0;
public int _BallScore3 = 0;
public int _TotalFrameScore = 0;
public bool _BowledStrike = false; //Did the bowler bowl a strike in this frame.
public bool _BowledSpare = false; //Did the bowler bowl a Spare in this frame.
//public Frames(){}
#region Constructors
public Frames(int FrameNum)
{
_FrameNum = FrameNum;
}
public Frames(int FrameNum, int BallScore1)
{
_FrameNum = FrameNum;
_BallScore1 = BallScore1;
}
public Frames(int FrameNum, int BallScore1, bool BowledStrike)
{
_FrameNum = FrameNum;
_BallScore1 = BallScore1;
_BowledStrike = BowledStrike;
}
public Frames(int FrameNum, int BallScore1, int BallScore2)
{
_FrameNum = FrameNum;
_BallScore1 = BallScore1;
_BallScore2 = BallScore2;
}
public Frames(int FrameNum, int BallScore1, int BallScore2, bool BowledSpare)
{
_FrameNum = FrameNum;
_BallScore1 = BallScore1;
_BallScore2 = BallScore2;
_BowledSpare = BowledSpare;
}
public Frames(int FrameNum, int BallScore1, int BallScore2, int BallScore3)
{
_FrameNum = FrameNum;
_BallScore1 = BallScore1;
_BallScore2 = BallScore2;
_BallScore3 = BallScore3;
}
#endregion
}