get the total valor float inside a Gameobject from a List
hi, i m trying to get the value of a float inside all the Gameobject in my List . i get a new item list everytime the player get inside some trigger. How i can get the value inside this gameobject ? normally, this variable is inside his script " nucleo ".
float totalElec;
public void Recoleccion( GameObject ho)
{
listadeNucleos.Add(ho);
foreach(GameObject x in listadeNucleos)
{
totalElec += x.GetComponent<nucleo>().elec;
}
}
thanks
Comment
Best Answer
Answer by Stonemass · Jan 18, 2021 at 03:15 PM
Thz community, i find the solution is just make a float variable and use the method Sum(); with no parameters :)
densidad = electrones.Sum();
Your answer
Follow this Question
Related Questions
Using foreach to remove and delete bullet in List - C# 3 Answers
How to select two 2D objects in order to make a third object 1 Answer
Missing GameObject, help!! 0 Answers
Cant loop through a List 2 Answers
Issue with a for loop. 0 Answers