简体   繁体   中英

Accessing from parent object a method from a script component located on a child

I've got an object player on which I've put a child which contains only a script casting a line to detect if the player is grounded. I'd like to get the result of this linecast in my playerControls script (component of player). To do this i've made a public methods that returns the result of the linecast, but I don't know how to make a reference to the script to call the method.

How can I do ?

https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html

 hingeJoints = GetComponentsInChildren<HingeJoint>();

If you only have one player you can also use a Singleton pattern. But the easier solution is to get the component of the child.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM