Have you looked at the game Object functions in the scripting manual. There are many examples in there. Just create a var for a gameObject and assign the doorFrame in the inspector and you can do whatever u want with it. There are many ways to get to it but just wondering what do u want to do with the frame?
There is only about a trillion ways you could find it, just depends how you’re setting up scripts/scene.
a) Could tag the “frame” and check its parent for the right door.
b) “door” could have references to each of its children objects.
c) GameObject.Find(“/wall/door2/frame”);
etc.
i know about that, but what if i have object selected and i dont anything about hierarchy, how to what is the first parent of the child? can i do it by looping trhough something? the reason i want to know this is that i have complex hierarchy with lot of sub sections, parents and childs, so the most convinient thing would be if i have a selected object, and that is the only information i need to know what is its parent and what other children are connected to it. (not master parent but the first parent, like door1 or door2 in the example above)
Without at least a bare minumum amount of structure/heirarchy to the scene, it’ll be slow as hell.
I’d loop thru the scene and create GameObject references with transform.Find(“Door”) for anything that might be used each Update.
sjarman: That’s because you are using Transform.Find:
There is also GameObject.Find:
For interest’s sake, go into the search window in the docs and type FIND. You’ll find an impressive list.
For more information on Transform.Parent:
Now specifically you can then find the GameObject from the Transform with:
var frameTransform : Transform = gameObject.transform.parent.Find("Frame");
var frameObject : GameObject = frameTransform.gameObject;
Now I think you can do this (but I’ve not tested it):
var frameTransform : Transform = transform.parent.Find("Frame");
… as I think ‘gameObject’ is redundant (*that being said, Dreamora is far more experienced than I am at coding!!)
And you might even be able to get away with:
var frameObject : GameObject = transform.parent.Find("Frame").gameObject;
… if you follow the logic, all crammed into one line.
Look at this page:
Scan thru Variables, and you’ll see that this is a list of all the properties of the Tansform (position, location, etc.). Now go down and look at Inherited Variables. You’ll see there reference to things (components, etc.) attached to this transform.
Now look back at the line you were using:
gameObject.transform.parent.Find("Frame")
This is saying “go to the gameObject attached to this transform” (Inherited Variable gameObject with lowerCase ‘g’) search the transform’s parent and find something called “Frame”.
If you look at the second line I wrote:
var frameObject : GameObject = frameTransform.gameObject;
It’s saying "From the transform of the thing called “Frame” that we remember as a variable called frameTransform, look for it’s GameObject (using the Inherited Variable gameObject with lowerCase ‘g’!) and remember a reference to it in a new variable called frameObject.
It is important to note this bit of information:
Dont’ forget to save this “find” to a variable that you can use later.
In the above examples if you have:
var frame : GameObject;
function Start () {
var frameTransform : Transform = gameObject.transform.parent.Find("Frame");
frame = frameTransform.gameObject;
}
function ActivateFrame () {
frame.active = true;
frame.renderer.material.color = Color.green;
// and whatnot... as you've saved a reference to "Frame"
}