0

I have a script inside a child gameobject , I want to disable it through coding on the parent Object ,help will be much appreciated,thanks.

edit:the script I want to carry out all the actions is not attached to the parent gameobject.

  • This is a million-times duplicate. – Fattie Feb 01 '16 at 12:04
  • Possible duplicate of [How do I enable Parts/Components in Unity C# with only a game object in the script](http://stackoverflow.com/questions/31993266/how-do-i-enable-parts-components-in-unity-c-sharp-with-only-a-game-object-in-the) – Fattie Feb 01 '16 at 12:04

1 Answers1

1

I hope this code is self commenting ;)

using UnityEngine;
using System.Collections;

public class ScriptAttachedToParent : MonoBehaviour 
{
    void Start () 
    {
        transform.GetChild (0).GetComponent<ScriptAttachedToChild> ().enabled = false;

        // OR
        //transform.Find("ChildGameObject").GetComponent<ScriptAttachedToChild> ().enabled = false;
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
Jerry Switalski
  • 2,690
  • 1
  • 18
  • 36