This may be a case of not having the right grammar or mindset, but I seem to have hit a wall here.
Explanation: I have a number of objects in the scene tagged as "ScoreObject", and each has a "CountScore" script that constantly increases the object's "myScore" variable.
I'm trying to calculate the total score accrued. Every 2 seconds, the score tracker script should check each object named "Score Object", get the value of all of their myScore variables, add them together, then add them to the scripts own "myScoreTotal". The number of ScoreObjects can vary in the game.
Now, I'm still learning, and the creation and accessing of Arrays is still a little foreign to me, so I ask for your patience and understanding (i.e. talk to me as if I was dumb.) I've got this so far, and I'm not even sure if this is good. I especially don't know how to get the variables contained within each object in the array (hence the title).
So basically, I would like to:
Thanks for your time.
asked Dec 22 '10 at 10:12 PM
You are very close. You just want to iterate through the array and add each value to your running total.
Let me also suggest a change that would not require you to Get the component every 2 seconds and will give you better performance.
Unity has an Object-Oriented programing style so you have to make sure that if you try and access a variable that is not part of your script, that you first find the object it is attached to in this case the ScoreObject component. That's another thing. Objects do not have to be GameObjects in fact most of them aren't.