- Home /
Question by
Will-D-Ramsey · Aug 20, 2016 at 09:41 AM ·
javascriptoptimizationchild objectlodlodgroup
Hows to assign an objects children to its LOD component?
Hello, I have trees with 2 lod levels. The trees work with a parent object (LOD group attached). This parent has 2 children (different tree objects). Im trying to find a way for my small LOD_Set script to set the parents children to its lod group component. So far I get an array index is out of range error. Line 13 //code attached
#pragma strict
var group : LODGroup;
function Start ()
{
var childs : LOD[] = new LOD[2];
var Lod0 : Renderer[] = new Renderer[2];
Lod0[1] = gameObject.transform.GetChild(0).gameObject.GetComponent(Renderer);
Lod0[2] = gameObject.transform.GetChild(1).gameObject.GetComponent(Renderer);
childs[0].renderers = Lod0;
group.SetLODS(childs);
group.RecalculateBounds();
}
Comment
At like 13, Lod0[2] is the 3rd element of Lod. But when defined, only 2 elements are constructed. So yea index out of range.
Should use Lod0[0], and Lod0[1] respectively
Your answer
Follow this Question
Related Questions
LOD from one file? 1 Answer
How to use Level of Detail in 2D Game ? 1 Answer
My LOD Group is not working? How do I use this.. 1 Answer
Making a GetComponent array 1 Answer