probably how the wheel is designed. the wheel rotates by itself and is parented to a dummy object that can rotate in y axis and in turn is connected to a dummy attached to the main object.
Sure it works, but it's bad design. If for some reason the hierarchy changes, your code stops working. If done right, you should never have to traverse a scene's hierarchy in code.
The other comments are correct, but I'd also point out that this could be an architectural problem, and that it is often better to attach scripts to the root object and - in the event that you need to read a cast or collision with a specific part, use transform.root. I'd go for GetComponentInParents when that isn't feasible.
The most straightforward and already much improved way would be to attach a component (e.g. "Wheel") to the target Game object, have it store the needed references and provide a method for getting them.
30
u/RedditAcc-92975 Dec 27 '21
uff, looking through cyberpunk leaked code?
73
u/STNeto1 Dec 26 '21
parent.parent.parent.gameObject
26
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 26 '21
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
17
u/polyworfism Dec 27 '21
I call this "23andMe" code
10
u/orangeoliviero Dec 27 '21
Seems like a bug workaround to me, probably left in just in case the bug returns.
9
u/andoy Dec 27 '21
probably how the wheel is designed. the wheel rotates by itself and is parented to a dummy object that can rotate in y axis and in turn is connected to a dummy attached to the main object.
2
u/rexpup Dec 27 '21
This is me trying to debug stuff happening in DOM trees
2
u/[deleted] Dec 27 '21
what is this family tree
1
u/babalaban Jan 10 '22
Talk about re-inventing a wheel