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.
Using Keywords
Hi,
Please could someone help me with the best way to setup using keywords within unity. I am trying to have it so that I can activate and deactivate two planes within my hierarchy by using my hololens with two separate words. Any suggestions would help. Thanks so much!
Best Answers
-
Optionstrzy ✭✭✭
It's not a method. It's a property (with a getter and a setter). These look like variables but are just syntactical sugar that make use of implicit method calls under the hood. Learn about them: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
Look at my code above again carefully. I use an assignment operation, not a method call.
Bart
http://trzy.org1 -
Optionsholonut ✭
I simplified things alot and got it to work!
I used the followingusing System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using UnityEngine;public class HideLayer : MonoBehaviour
{
public void showHidePlane()
{
if(GetComponent().enabled == true)
{
GetComponent().enabled = false;
}
else
{
GetComponent().enabled = true;
}
}
}Thanks for everyone that helped!
0
Answers
I have implemented Keywords Manager into Unity and it seems to work with changing the color of my plane. Can anyone help me with writing c# script to enable and disable Mesh Render using one keyword?
Thanks again!
Should be as simple as calling GetComponent < MeshRenderer > ().enabled = false or true.
Bart
http://trzy.org
I am still getting an error of unityengine.renderer.enable cannot be used as a method... This is the code that I am using:
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using UnityEngine;
public class HideLayer : MonoBehaviour
{
public void showhidePlane()
{
if (gameObject.GetComponent().enabled != true)
gameObject.GetComponent().enabled (true);
else
gameObject.GetComponent().enabled (false);
}
}
Thanks
It's not a method. It's a property (with a getter and a setter). These look like variables but are just syntactical sugar that make use of implicit method calls under the hood. Learn about them: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
Look at my code above again carefully. I use an assignment operation, not a method call.
Bart
http://trzy.org
just attach this to your object:
You also could try
GetComponent<Renderer>().setActive = true;
Thank you, I have done a lot of educational training over the last 12 hours. Unfortunately my coding experience is still beginning. I am now going though a full online c# course. That still does not answer my problem at hand. The get/set examples that I have referenced online are simple in structure. They do not show how to add "if" logic with getter/setter accessor properties.
It is probably simple to you but now code is saying "Cannot implicitly convert type 'bool' to 'string'
I know that it is not only a true/false statement but I dont know how else to declare the variables.
I will keep working on it but direction from anyone would be appreciated.
Thanks!
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using UnityEngine;
public class HideLayer : MonoBehaviour
{
public string meshRenderer { get; set;}
public string Aquifer { get; set;}
public string ResetAquifer { get; set;}
}
I simplified things alot and got it to work!
I used the following
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using UnityEngine;
public class HideLayer : MonoBehaviour
{
public void showHidePlane()
{
if(GetComponent().enabled == true)
{
GetComponent().enabled = false;
}
else
{
GetComponent().enabled = true;
}
}
}
Thanks for everyone that helped!