Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

How can I access another class's (public) variable?

I'm trying to use the IsBeingPlaced bool from the HoloToolkit's TapToPlace script in a separate class so I can track the placement of several objects, but I don't know how to access the bool attached to each individual object's TapToPlace.

Each object in my scene individually implements the TapToPlace script, but they share the same parent which implements my own script to add other functions. Is there a way to access the bool of each individual object in the parent's script, or perhaps another way I can achieve the same effect of tracking each object's placement? I'm still pretty new to C# and Unity so any advice would be greatly appreciated.

Thanks in advance,
Ben

Tagged:

Best Answer

  • Options
    FrimyFrimy
    edited June 2017 Answer ✓

    Hey,

    You can get your public bool using this code in your parent script(not tested, but the idea is there), in a loop to get all children:
    bool isBeingPlaced = this.gameObject.transform.GetChild("index of your child").gameObject.GetComponent<"Your script">().IsBeingPlaced;

Answers

  • Options
    FrimyFrimy
    edited June 2017 Answer ✓

    Hey,

    You can get your public bool using this code in your parent script(not tested, but the idea is there), in a loop to get all children:
    bool isBeingPlaced = this.gameObject.transform.GetChild("index of your child").gameObject.GetComponent<"Your script">().IsBeingPlaced;

  • Options

    That did the trick, thanks!

Sign In or Register to comment.