[SOLVED with example] Sync GlobalLight and personal Flashlight Over the Network

Hey!

i’ve been having a hardtime trying to make a small co-op game, it’s my first time trying this and although there are other questions about this in the forum, most seems to be pretty old or unsolved, can anyone please help me put a light on this ?

This first script is meant to sync flashlights on the players, each player have its own flashlight that other players can see. Just won’t work, players only see their own light.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.Characters.FirstPerson;

public class NetworkPlayer : NetworkBehaviour {

    public GameObject FPSCamera;
    public CharacterController characterControler;
    public FirstPersonController FPScontroler;

    //Related to the flashLight EachPlayer should carry. The "Luz" in this Script is the Flashlight ... yeah, named poorly.
    [SerializeField] private Light Luz;
    [SyncVar] private bool LightState;

    //The global Spotlight that should have its intensity changed according to.
    public GameObject SpotLight;

    private void Start ()
    {

        if (!isLocalPlayer) {
            FPSCamera.SetActive (false);
            characterControler.enabled = false;
            FPScontroler.enabled = false;
        }        
    }

    private void Update ()
    {           

        if (Input.GetButtonDown ("AniF"))
        {
            if (isLocalPlayer)
            {
                Luz.enabled = !Luz.enabled;               
                Debug.Log (LightState);
            }
            GetLightValue ();
            SendLightValue ();
        }
        if (Input.GetButtonDown ("AniE"))
        {
            if (isLocalPlayer)
            {
                //This part should call the Method in the "UltimaLightCorrecting.cs" to change the intensity of the global "SpotLight".
                SpotLight .GetComponent<UltimaLightCorrecting>(). AddTheTHING();
            }
        }


    }
    private void GetLightValue()
    {
        if (!isLocalPlayer)
        {
            Luz.enabled = LightState;
        }
    }

    [ClientCallback]
    private void SendLightValue()
    {
        if (isLocalPlayer == true)
        {
            CmdSendLightValue();
        }
    }

    [Command]
    private void CmdSendLightValue()
    {
        LightState = Luz.enabled;
    }
}

And this is a Global light that should have its intensity changed for everyone … also not working properly…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class UltimaLightCorrecting : NetworkBehaviour {

    //The "SpotLight" on the other Script is called here named "Luz", But its the same object...
    public Light Luz;
    [SyncVar] public float IntLuz;

    void Update ()
    {
        ClientRecoverState ();
        if (isServer) {
            RpcClientSpread ();
        }

    }

    //Am I suppose to use this?
    [ClientRpc]
    void RpcClientSpread ()
    {
        Luz.intensity = IntLuz;
    }

    //or this?
    [ClientCallback]
    void ClientRecoverState ()
    {
        Luz.intensity = IntLuz;
    }

    //This should be called by the "NetworkPlayer.cs" attached to the player.
    public void AddTheTHING ()
    {
        CmdAddFloat();
    }

    [Command]   
    public void CmdAddFloat()
    {
        if (IntLuz <= 10) {           
            IntLuz++;
        } else
        {
            IntLuz = 0f;
        }
    }
}

Thanks in advance for any help or advice given!

You should use Cmd’s to toggle lights on the server. And then either listen to value change, or use Rpc to change light states on the other clients.

Note that you don’t need to sync SyncVar’s manually, this will actually cause desynchronization. Also remember that SyncVars are Server->Client direction only.

1 Like

A SyncVar controlled by the server should work OK for the light. The client can then tell the server when his light is on.

Something like this
1: Client tells Server light is On/Off by [Command]
2: Server receives command and sets the SyncVar accordingly
3: All clients receive the SyncVar hook and set the light.intensity or enabled.

1 Like

Thanks for the reply!

i did some changes to the code, still don’t know how to use the SyncVar Hook properly but i got some results…

about the Flashlight:
Opened 3 instances, every client see the host flashlight changing state but the client lights shows no change on each other screens.

about the Global Light:
Used a ClientRpc and the light changes intensity in all of them, but once i press “F” in any other instance, the value resets to that one instance, like the SyncVar is not syncing the “LightInt”, its only that the Rpc changing the “LightExtern” value on the host and clients.

I feel like i’m very close, what am i missing?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.Characters.FirstPerson;

public class NetworkPlayer : NetworkBehaviour {

    public GameObject FPSCamera;
    public CharacterController characterControler;
    public FirstPersonController FPScontroler;


    //Related to the flashLight EachPlayer should carry.
    [SerializeField] private Light FlashLight;
    [SyncVar] private bool LightState;


    //Related to the Global Light every player should see.
    [SyncVar] public int LightInt;
    //This was suppost to be an output so other Lights could access it.
    public static int LightExtern;



    private void Start ()
    {

        if (!isLocalPlayer) {
            FPSCamera.SetActive (false);
            characterControler.enabled = false;
            FPScontroler.enabled = false;
        }        
    }

    private void Update ()
    {       
            GetLightValue ();

        //FOR FLASHlIGHT
            if (Input.GetButtonDown ("AniF"))
            {
               
                if (isLocalPlayer == true)
                {
                FlashLight.enabled = !FlashLight.enabled;                   
                    Debug.Log (LightState);
                }               
                SendLightValue ();
            }

        //FOR GLOBAL lIGHT
            if (Input.GetButtonDown ("AniE"))
            {
                if (isLocalPlayer == true)
                {               
                CmdAddIntGlobalLight();
                }
        }


    }
    //FOR FLASHlIGHT.
    private void GetLightValue()
    {
        if (!isLocalPlayer)
        {
            FlashLight.enabled = LightState;
            //CmdGetLightValue ();
            Debug.Log ("Not-Local Player from GetLightValue Executed - FlashLight Updated here.");
        } else {
            Debug.Log ("Local Player from GetLightValue Executed - Don't Update FlashLight here.");
        }
    }

    //FOR FLASHLIGHT. not in use.
    [Command]
    private void CmdGetLightValue()
    {
        FlashLight.enabled = LightState;
    }
    //FOR FLASHlIGHT.
    private void SendLightValue()
    {
        if (isLocalPlayer == true)
        {
            CmdSendLightValue();
            Debug.Log ("Cliente Call Executed.");
        }   
    }

    //FOR FLASHlIGHT.
    [Command]
    private void CmdSendLightValue()
    {
        LightState = FlashLight.enabled;
        Debug.Log("Switched the FlashLight state.");
    }
       
    //FOR GLOBAL lIGHT
    [Command]
    void CmdAddIntGlobalLight()
    {
        LightInt++;
        Debug.Log (LightInt);
        Debug.Log ("Added Intensity to Global Light.");
        RpcLightIntSpread ();
    }

    //FOR GLOBAL lIGHT
    [ClientRpc]
    public void RpcLightIntSpread()
    {
        LightExtern = LightInt;
    }
}

My problem is half solved.

I managed to sync the Flashlights that each player carry but not the Global light and i’ll explain a little better my limitations …

For now, the FlashLight sync code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.Characters.FirstPerson;

public class NetworkPlayer : NetworkBehaviour {

    public GameObject FPSCamera;
    public CharacterController characterControler;
    public FirstPersonController FPScontroler;


    //Related to the flashLight EachPlayer should carry.
    [SerializeField] private Light FlashLight;
    [SyncVar] private bool LightState;

    private void Start ()
    {

        if (!isLocalPlayer) {
            FPSCamera.SetActive (false);
            characterControler.enabled = false;
            FPScontroler.enabled = false;
        } else {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = true;
        }
    }

    private void Update ()
    {       
            GetLightValue ();
            //FOR FLASHlIGHT
            if (Input.GetButtonDown ("AniF"))
            {
               
                if (isLocalPlayer == true)
                {
                bool ChangState = !LightState;                   
                Debug.Log (LightState);
                CmdSendLightValue(ChangState);
                }               
                //SendLightValue ();
               
            }


    //---------------------------------------------

    }
    //FOR FLASHlIGHT.
    private void GetLightValue()
    {
        FlashLight.enabled = LightState;
    }

    //FOR FLASHlIGHT.
    [Command]
    private void CmdSendLightValue(bool ChangState)
    {
        LightState = ChangState;
        Debug.Log("Switched the FlashLight state.");
    }


    //---------------------------------------------

       

}

So, the issue i’m having with the Global light is that i want that script to not be attached to the player so i have more flexibility to design the level. The issue comes cuz no object aside from the LocalPlayer has authority to use Commands, so i can’t change the variable (set with [SyncVar]) of the script attached to the item in the scene. If i make the value Static, then [SyncVar] won’t update across the board… so i’m kind of stucked with it.

Spawning the objects from the server is also not an option, since i’d need to defy spawnpoints from everything and call from script, not being able to with them in the inspector.

Is there any way to give a random Object authority enough so it can call [Commands] by its own? it another way around it?

You can change that variable by accessing it via object that has authority on the server. Just redirect it in [Command].

1 Like

You mean doing something like:

Client/Host/Whatever > Mediator Server-only Script > Random Object ?

i’ll give it a shot right now, thanks for the quick answer!

i was going for something more complicated lol like using a raycast to gather info from the object and forcefully change it, but i’m having issues with authority, identities and my client still can’t change it …

My raycast attached to the camera, not the FPScontroller itself:

using UnityEngine;
using UnityEngine.Networking;

public class Raycast : NetworkBehaviour//<----
{
    //The Raycast.
    public static float DistanceFromTarget;//Use This.
    public float ToTarget;

    //About the Target. -----------------------------------------------
    [SerializeField] private GameObject ObjectHitted;//The real object hitted.
    [SerializeField] private NetworkIdentity TargetId;

    public static string TargetName;//Use this.
    public string ObjectName;
   
    //public string PuzzleType;

    //Triggers related to the Raycast.
    public bool ReadyToHit;

    //About the Target. -----------------------------------------------

    void Update()
    {
            RaycastHit hit;
            Vector3 forward = transform.TransformDirection (Vector3.forward) * 2.5f;
            Debug.DrawRay (transform.position, forward, Color.blue);

            if (Physics.Raycast (transform.position, (forward), out hit))
            {
            //Gather Actual distance in Float.
            ToTarget = hit.distance;
            //Just to make it a norm.
            DistanceFromTarget = ToTarget;
               

            //Gather the Name of the Object hitting.
            ObjectName = hit.collider.gameObject.name;
            //Just to make it a norm
            TargetName = ObjectName;

            }
           
            if (DistanceFromTarget <= 2.5f)
            {

            //Gets the Proximity value from the UniversalPuzzle.cs.
            ReadyToHit = UniversalPuzzle.Proximity;
            //ReadyToHit = ObjectHitted.GetComponent<UniversalPuzzle> ().Proximity;


            if (ReadyToHit == true)
                {
                    if (Input.GetButtonDown ("AniE"))
                    {
                    //THIS IS THE TRUE BUSINESS.------------------------------------------------

                    //Gather the Actual GameObject.---------------------------------------------
                    ObjectHitted = GameObject.Find (ObjectName);
                    Debug.Log (DistanceFromTarget);
                    Debug.Log ("Object Hitted is" + ObjectHitted);
                    Debug.Log ("Object Name is" + TargetName);
                    //Get the GameObject Raycast hit NetworkIndentity.
                    TargetId = ObjectHitted.GetComponent<NetworkIdentity> ();
                    Debug.Log (TargetId);
                    //--------------------------------------------------------------------------

                    //Assing Authority.
                    TargetId.AssignClientAuthority (connectionToClient);

                    ChangeTextoState();

                    //Remove Authority.
                    TargetId.RemoveClientAuthority (connectionToClient);

                    Debug.Log ("Got here");
                                   


                    //--------------------------------------------------------------------------
                    }
                }

            }

    }
    //TODO:Need to be fixed from the Client side.
    public void ChangeTextoState()
    {
        if (ObjectHitted.GetComponent<UniversalPuzzle> ().TextoState == true) {
            ObjectHitted.GetComponent<UniversalPuzzle> ().TextoState = false;
            Debug.Log ("Desligou");
        } else {
            ObjectHitted.GetComponent<UniversalPuzzle> ().TextoState = true;
            Debug.Log ("Ligou");
        }
        Debug.Log ("O TextoState do UltimaPuzzle está" + ObjectHitted.GetComponent<UniversalPuzzle> ().TextoState);
    }

    //---------- FINAL --------
}

and the Object was like:

public class UniversalPuzzle : NetworkBehaviour {

    public float TheDistance;//The distance calculated by the Raycast.
    public GameObject PressEtoInteract;//Text Showing that it's ready to interact.
    public static bool Proximity; //Verify proximity for activation.
    public GameObject Texto1; //Text that should activate/deactivate.

    //RELATED  TO THE ACTVATION ------------------------------------------------
    [SyncVar(hook="ChangeSyncValue")] public bool TextoState;            //Goes FROM server TO client.
    public static bool ExternalBool;
    //RELATED  TO THE ACTVATION ------------------------------------------------

    // Update is called once per frame
    void Update () {
       
        TheDistance = Raycast.DistanceFromTarget;

        //Actvation of TEXTO1

        ExternalBool = TextoState;

        //-----------------------------------------------------------------

    //FOR RAYCAST CALCULATION and PERMITION.
        if (TheDistance >= 2.5)
        {
            PressEtoInteract.SetActive(false);
            Proximity = false;
        }
    }

    //FOR RAYCAST CALCULATION.
    void OnMouseOver()
    {

        //If closer than 2.5f, proximity gets true, therefore, "ReadyToHit" also becomes true.
        if (TheDistance <= 2.5) {
            PressEtoInteract.SetActive (true);
            Proximity = true;
        } else
        {
            PressEtoInteract.SetActive(false);
            Proximity = false;
        }
    }

    //FOR RAYCAST CALCULATION.
    void OnMouseExit()
    {
        PressEtoInteract.SetActive(false);
        Proximity = false;
    }

    //[ClientRpc]
    [Client]
    //[ClientCallBack]
    //[Command]
    void ChangeSyncValue(bool NewValue)
    {
        Debug.Log ("Hook Worked");
        Texto1.SetActive(NewValue);
    }

Well I meant you still need authority to issue commands. You can do something like:
Client (Object with authority) → CmdToSameObjectOnTheServer → Obtain ref for that variable → Server.Var change

[Command]
public void CmdChangeSomething(#BasicTypesForDataExchange#){
    .. Access object here
    ... Change var or call method or whatever
}
1 Like

So, first of all i want to thank the forum for the answers given, i looked a lot to a solution out there but this thread really helped me to find a path to follow about it.

I wanted to interact with object that i just added to the scene and attached a script to it, not needing to make the whole work happen in a huge script on the player and make the scene objects be a mere reference for where to access.

Trying to make a box light a light globally from a script attached to the box wasn’t working because the box, unless spawned by the server, wouldn’t have authority to use [Commands] to change it’s own SyncVar Variables. The solution lays on making the player a conduit for the commands, so the instead of making the box change things, the player “ask” the box what’s going on inside it and change it himself. By asking the box for details i avoided having a HUGE script attached to player and can indeed store variables and information on scene objects, as long i program the Player to access it.

The file itself lies here, there is a box and when you press E to interact with, it switch the light on/off.

i made lot of comments on the script itself on the file, but if you want to see it here:

First, the NetworkPlayer which also controls the personal Flashlight

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.Characters.FirstPerson;

public class NetworkPlayer : NetworkBehaviour {

    public GameObject FPSCamera;
    public CharacterController characterControler;
    public FirstPersonController FPScontroler;


    //Related to the flashLight EachPlayer should carry.
    [SerializeField] private Light FlashLight;
    [SyncVar] private bool LightState;

    private void Start ()
    {

        if (!isLocalPlayer) {
            FPSCamera.SetActive (false);
            characterControler.enabled = false;
            FPScontroler.enabled = false;
        } else {

            //If you're the LocalPlayer this will lock the cursor in the center of the screen so i the "MouseOver" and "MouseExit" functions will work properly.
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = true;
        }
    }

    private void Update ()
    {       
            GetLightValue ();
            //FOR FLASHlIGHT
            if (Input.GetButtonDown ("AniF"))
            {
               
                if (isLocalPlayer == true)
                {
                bool ChangState = !LightState;                   
                Debug.Log (LightState);
                CmdSendLightValue(ChangState);
                }               
                //SendLightValue ();
               
            }

    //---------------------------------------------

    }
    //FOR FLASHlIGHT.
    private void GetLightValue()
    {
        FlashLight.enabled = LightState;
    }

    //FOR FLASHlIGHT.
    [Command]
    private void CmdSendLightValue(bool ChangState)
    {
        LightState = ChangState;
        Debug.Log("Switched the FlashLight state.");
   }

    //---------------------------------------------        

}

Here is the script that is used to gather the information of the target, the method chosen to “ask” information to the box:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Raycast : NetworkBehaviour//<----
{
    //The Raycast.
    public static float DistanceFromTarget;//Use this when accessing from other scripts.
    public float ToTarget;
    //Triggers related to the Raycast.
    public bool ReadyToHit;

    //About the Target. -----------------------------------------------
    [SerializeField] private GameObject ObjectHitted;//The real object hitted.
    [SerializeField] private NetworkIdentity TargetId;

    public static string TargetName;//Use this when accessing from other scripts.
    public string ObjectName;
 
    public float PuzzleType;

    //About the Target. -----------------------------------------------

    //The "Mediator". -------------------------------------------------
    [SerializeField] private GameObject ThisObject;
    void Start ()
    {
        //ThisObject = this;
    }

    //The "Mediator". -------------------------------------------------

    void Update()
    {
            RaycastHit hit;
            Vector3 forward = transform.TransformDirection (Vector3.forward) * 2.5f; //is the length of the blue line that shows on the scene.
            Debug.DrawRay (transform.position, forward, Color.blue); //the color of that line.

            if (Physics.Raycast (transform.position, (forward), out hit)) //Only works if it acutally hits something.
            {
            //Gather Actual distance in Float.
            ToTarget = hit.distance;
            //Just to make it a norm.
            DistanceFromTarget = ToTarget;               

            //Gather the Name of the Object hitting.
            ObjectName = hit.collider.gameObject.name;
            //Just to make it a norm
            TargetName = ObjectName;


            }           
            if (DistanceFromTarget <= 2.5f)
            {

            //Gets the Proximity value from the UniversalPuzzle.cs.
            ReadyToHit = UniversalPuzzle.Proximity;

            if (ReadyToHit == true)
                {
                    if (Input.GetButtonDown ("AniE"))
                    {
                    //THIS IS THE TRUE BUSINESS.------------------------------------------------

                    //Gather the Actual GameObject.---------------------------------------------
                    //Everything Works Here
                    ObjectHitted = GameObject.Find (ObjectName);
                    PuzzleType = ObjectHitted.GetComponent<UniversalPuzzle> ().PuzzleTypeInside;
                    TargetId = ObjectHitted.GetComponent<NetworkIdentity> ();
                    Debug.Log ("PuzzleType " + PuzzleType);
                    Debug.Log ("Distance from the Raycast " + DistanceFromTarget);
                    Debug.Log ("Object Hitted is" + ObjectHitted);
                    Debug.Log ("Object Name is" + TargetName);
                    Debug.Log ("The boolState from UltimaPuzzle is = " + ObjectHitted.GetComponent<UniversalPuzzle> ().boolState);
                    Debug.Log ("The Object Network Target ID is " + TargetId);
                    //--------------------------------------------------------------------------

                    /*I know i called many Components in the lines before, but you only really need provide the GameObject and the PuzzleType to the Mediator.
                    Anything information this script can acess, the Mediator also is allow to gather, so we only need to give it a base where to look for and
                    what to look for*/
                    ThisObject.GetComponent<Mediator>().FilterPuzzleType(ObjectHitted, PuzzleType);

                    //--------------------------------------------------------------------------
                    }
                }

            }

    }
    //---------- FINAL --------
}

This is the Script that is attached to the box, it’s responsible for proving any information “asked” AND controlling the “Press E to interact” text that shows when you get closer:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class UniversalPuzzle : NetworkBehaviour {

    //FOR RAYCAST CALCULATION.--------------------------------------------------------------------------------

    public GameObject PressEtoInteract;//Text Showing that it's ready to interact.
    public float TheDistance;//The distance calculated by the Raycast.
    public static bool Proximity; //Verify proximity for activation.
    public static string NameOfThisPuzzle;

    [SyncVar] public float PuzzleTypeInside = 1;


    //Variables for Type 1 ------------------------------------------------
    [Header("Variables related to the Type 1 Puzzletype")]
    [SyncVar] public GameObject RandomObject; //Text that should activate/deactivate.
    [SyncVar(hook="ChangeSyncValue")] public bool boolState; //Goes FROM server TO client.

    //RELATED  TO THE ACTVATION ------------------------------------------------

    void Start ()
    {

    }
    //The SyncVar hook calls the "ChangeSyncValue". and i called every Method i know to make the effect spread across the board.--------------
    //I don't really know which one to use here ... so i called all of them lol.

    /*A quick Explanatio of how SyncVar hook works, everytime that one var changes, it automatically calls the Method assigned to the hook and
     * the value inside (value here, whatever the name might be) is the new value of that var. */

    //TYPE 1 --------------------------------------------------------------------
    public void ChangeSyncValue(bool NewValue)
    {
        Debug.Log ("Hook Worked Bool");
        RandomObject.SetActive(NewValue);

        ChangeByClientCallBack (NewValue);
        RpcChangeByRpc (NewValue);
        CmdChangeByCommand (NewValue);
    }
    [ClientCallback]
    void ChangeByClientCallBack(bool NewValue2)
    {
        RandomObject.SetActive(NewValue2);
        Debug.Log ("CallBack Worked");
    }

    [ClientRpc]
    void RpcChangeByRpc (bool NewValue2)
    {
        RandomObject.SetActive(NewValue2);
        Debug.Log ("Rpc Worked");
    }

    [Command]
    void CmdChangeByCommand (bool NewValue2)
    {
        RandomObject.SetActive(NewValue2);
        Debug.Log ("Command Worked");
    }
    //TYPE 1 --------------------------------------------------------------------


    //----------------------------------------------------------------------------------------------------------------------------------------
       
    void Update () {
    //FOR RAYCAST CALCULATION.   
        TheDistance = Raycast.DistanceFromTarget;
    //For Raycast calculation - it directs to the Proximity variable is it's close enough to interact.

        //Do things


    //FOR RAYCAST CALCULATION.--------------------------------------------------------------------------------
        if (TheDistance >= 2.5)
        {
            PressEtoInteract.SetActive(false);
            Proximity = false;
        }
    }
       
    void OnMouseOver()
    {

        //If closer than 2.5f, proximity gets true, therefore, "ReadyToHit" also becomes true.
        if (TheDistance <= 2.5) {
            PressEtoInteract.SetActive (true);
            Proximity = true;
        } else
        {
            PressEtoInteract.SetActive(false);
            Proximity = false;
        }
    }
       
    void OnMouseExit()
    {
        PressEtoInteract.SetActive(false);
        Proximity = false;
    }
    //--------------------------------------------------------------------------------------------------------   

}

And here is the “Mediator”, the script attached to the Player with LocalAuthority that process the information from the box:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Mediator : NetworkBehaviour {

    [SerializeField] private GameObject GatherObj;
    [SerializeField] private int GatherType;
    [SyncVar] private int Currency;
    private bool GatherBool;
    private NetworkIdentity GatherID;

    public void FilterPuzzleType (GameObject TheObject, float Type)
    {
        if (Type == 1) {
            CmdInputT1 (TheObject, Type);
        }
    }
       

    [Command]
    public void CmdInputT1 (GameObject TheObject, float Type)
    {       
        Debug.Log ("Went this far.");
        if (TheObject.GetComponent<UniversalPuzzle> ().boolState == true) {
            TheObject.GetComponent<UniversalPuzzle> ().boolState = false;
            Debug.Log ("Off.");
        } else {
            TheObject.GetComponent<UniversalPuzzle> ().boolState = true;
            Debug.Log ("On.");
        }
        Debug.Log ("boolState is " + TheObject.GetComponent<UniversalPuzzle> ().boolState);
    }
}

This problem is very simple… but was extremely hard to find a solution for, you guys taught me the logic to follow but i ended up writing the code myself cuz i couldn’t find references for these. I still have tons to learn and i hope this help someone out there in need.