- Home /
String to Var
I'm trying to reference multiple children of the current gameobject via a for loop, but I can't for the life of me get the string ("chainConnect"+i) to read as a variable. Any help would be greatly appreciated.
chainConnect1 through chainConnect 8 are children of the current gameobject.
function drawBeams() {
myLineRenderer.Clear();
for(i=0;i<occupiedSpaces.length;i++) {
myLineRenderer[i] = transform.Find("chainConnect"+i);
print(myLineRenderer[i]);
}
}
Thanks,
Tom
Answer by Julien-Lynge · Sep 29, 2011 at 04:53 AM
Tom,
What error or weird behaviour are you getting? I'm not a JS programmer, but can you simply typecast the i to a string before adding it ("chainConnect"+i.toString() or "chainConnect"+String(i))? Alternatively, it looks like you never explicitly type i as an int; you could try setting var i : int = 0.
Good luck.
Your answer
Follow this Question
Related Questions
How can I find a unique sibling/parent/child in a specific hierarchy and not from all the scene? 1 Answer
How to call a child by tag or name 1 Answer
NullReferenceException when transform.Find(string) STILL 1 Answer
Find gameobject with name and if child of Player 1 Answer
Why GameObject.Find() work and parent.transform.Find() doesn't work? 1 Answer