Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

How do I disable ONLY the component of a child object and not the parent?

$
0
0
I have a puzzle piece that I move by dragging with the mouse Th puzzle piece is made of a parente gameObject witha collider2D an other things(collider used for dragging) and two, three or four child gameObjects that have each a collider2D(these work as the teeth that a puzzle piece has to assemble with another piece) While I drag it I want to disable the collider from all the child game objects so that only the piece collider can collide with the another piece´s teeth But when I run my code all of the colliders, including the parent gameObject collider, get disabled and get this error: NullReferenceException: Object reference not set to an instance of an object This is the part of the script in the parent gameObject that is supposed to make it happen(disaable only the colliders in children): ''' GameObject[] children; void Start() { children = gameObject.GetComponentsInChildren(); } private void Update () { ... foreach (GameObject collider in children) { collider.GetComponent().enabled = false; Debug.Log("Hijo desactivado:" + collider.gameObject.name); } ... } How do I disable ONLY the component of a child object and not the parent?

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>