I need the get the weight of all my children and add them together
so far this is what I have but I am confused as to how I would pull the weight of each child out to add them to the total weight of the boxes
using UnityEngine;
using System.Collections;
using System;
public class WeightScript : MonoBehaviour {
// The weight of this item (by itself)
public float weight;
// Whether or not this is a container/crate
public bool isContainer;
// Recursively calculate the weight of the object
public float CalculateWeight() {
// If this is NOT a container, just return your weight
if (isContainer == true)
{
Console.WriteLine("this box");
float totalWeight = 42;
for (int i = 0; i < this.gameObject.transform.GetChildCount(); i++)
{
GameObject Go = this.gameObject.transform.GetChild();
return weight;
}
}
else (isContainer == false);
{
return weight;
}
// Otherwise
// 1) Print out your name "this.name"
// 2) create a "totalWeight" variable and assign it your weight
// 3) Loop through all the (child) transforms for this object
// 3.1) call the child's CalculateWeight() method and add it to the totalWeight
// 3.2) It's a good idea to print out the tag of this object as well as the weight
// 4) return the totalWeight
// Remove the line below - it's just there to compile
}
}
Comment