Getting values from multiple objects

Hi guys!
I’ve got multiple rigidbodies, which all detect the amount of collision force they recieve.
I’ve created a “Score”-object, which I want to display the added score with just a simple GUI text for now.
All the colliding objects have a script with a public float variable “damageReceived”.
Now, I would like to collect all these “damageReveived” values to my “Score” object.
Is it possible to send the values to the “Score”-object, or should the “Score”-object collect them somehow?
And of course the score object should add all the values together gathered during the gameplay.
Am I approaching this in a completely wrong way?
I’m getting quite confused with the GetComponent -stuff here :slight_smile:


Assuming you have your rigidbody objects stored in an array or list: Just cycle through them whenever you want to tally your score, and for each one, use something like

using System.Collections.Generic;

public List<GameObject> rigidbodyList;

public void CheckTotalScore() {

    foreach(GameObject go in rigidbodyList) {
    Score.GetComponent<ScoreScript>().TotalScore += go.GetComponent<ScriptName>().damageReceived;