Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

One Script Referred by Another Script used by Multiple Objects

Discussion in 'Scripting' started by JeevanjotSingh, Feb 5, 2017.

  1. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    Hi,
    I created a script that have some Boolean variable and I want my second script to be work like how that Boolean reacts and then it applies some basic code to the objects as per Boolean decision from script one (parent script) .

    Problem -->

    I have multiple objects contained second script (child script) , and when ever i clone or duplicate the object in Scene view then the whole Boolean work passed there and old object not effected by it (Only script works for new created object) , Inside old objects the script not get disable , it stays enabled but just not work for Boolean Decision in Script One(Parent Script) .

    I am getting reference of Parent script like this :--

    Code (CSharp):
    1.         UiManager uimanagerscript;
    2.         public GameObject uimanager;
    3.  
    4.    
    5.  
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.             uimanager = GameObject.Find("UI-Manager");
    10.             uimanagerscript = uimanager.GetComponent<UiManager>();
    11.  
    12.     }
     
  2. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    You are getting the parent reference correctly.
    How is the parent Boolean property referenced in the child script?
    Is the problem only one instance of the child script is able to reference the parent Boolean property?
     
unityunity