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

Fade Out Canvas

I am trying to fade out my canvas using canvas group but cannot seem to get it to work.

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR.WSA.Input;
using HoloToolkit.Unity;
using System.Threading;
using System.Collections;

public class ToggleSwitch : Singleton
{
public bool isOn = false;
Renderer rend;
Renderer middleRend;
Renderer outerRend;
Renderer centerRend;
GameObject voiceCommands;
GameObject switchData;
public CanvasGroup canvasGroup;

public string urlOn()
{
    string r = "";
    r += ((int)UnityEngine.Random.Range(1000000, 8000000)).ToString(); //used to randomize url so same url in cache is not used
    r += ((int)UnityEngine.Random.Range(1000000, 8000000)).ToString();
    string result = "http://192.168.1.112/socket1On?p" + r; //url of switch turnOn
    return result;
}

public string urlOff()
{
    string r = "";
    r += ((int)UnityEngine.Random.Range(1000000, 8000000)).ToString(); //use to randomize url so same url in cache is not used
    r += ((int)UnityEngine.Random.Range(1000000, 8000000)).ToString();
    string result = "http://192.168.1.112/socket1Off?p" + r;    //url of switch turnOff
    return result;
}


// Use this for initialization
void Start()
{
    //rotate = false;
    voiceCommands = GameObject.Find("VoiceCommands");
    switchData = GameObject.Find("SwitchData");
    //StartCoroutine(Fade());
}

/* IEnumerator Fade()
{
yield return new WaitForSeconds(30);
}*/

public void onAirTap()
{
    isOn = !isOn; //switch states of switch
    GameObject center = GameObject.FindGameObjectWithTag("centerTriangle");  //get gameobject components of object with tag="centerTriangle"
    rend = center.GetComponent<Renderer>();  //get render components of game object with tag centerTriangle
    if (!isOn)
    {
        rend.material.color = new Color(0, 255, 0); //render green
        WWW www = new WWW(urlOn()); //toggle light on
    }
    if (isOn)
    {
        rend.material.color = new Color(255, 0, 0); //render red
        WWW www = new WWW(urlOff()); //toggle light off
    }
}

public void TurnOn()
{
    isOn = !isOn;
    rend.material.color = new Color(0, 255, 0);
    WWW www = new WWW(urlOn());
}

public void TurnOff()
{
    isOn = !isOn;
    rend.material.color = new Color(255, 0, 0);
    WWW www = new WWW(urlOff());
}

public void OnGazeEnter()
{
    voiceCommands.SetActive(true);
    switchData.SetActive(true);

    GameObject centerTriangle = GameObject.FindGameObjectWithTag("centerTriangle");
    GameObject middleTriangle = GameObject.FindGameObjectWithTag("middleTriangle");
    GameObject outerTriangle = GameObject.FindGameObjectWithTag("outerTriangle");
    centerRend = centerTriangle.GetComponent<Renderer>();
    middleRend = middleTriangle.GetComponent<Renderer>();
    outerRend = outerTriangle.GetComponent<Renderer>();
    if (isOn)
    {
        centerRend.material.color = new Color(255, 0, 0, 1.0f);
    }
    if (!isOn)
    {
        centerRend.material.color = new Color(0, 255, 0, 1.0f);
    }
    middleRend.material.color = new Color(255, 255, 255, 0.5f);
    outerRend.material.color = new Color(0, 0, 255, 1.0f);

}

public void OnGazeLeave()
{

    FadeMe();
    //voiceCommands.SetActive(false);
    //switchData.SetActive(false);
    GameObject centerTriangle = GameObject.FindGameObjectWithTag("centerTriangle");
    GameObject middleTriangle = GameObject.FindGameObjectWithTag("middleTriangle");
    GameObject outerTriangle = GameObject.FindGameObjectWithTag("outerTriangle");
    centerRend = centerTriangle.GetComponent<Renderer>();
    middleRend = middleTriangle.GetComponent<Renderer>();
    outerRend = outerTriangle.GetComponent<Renderer>();
    if (isOn)
    {
        centerRend.material.color = new Color(255, 0, 0, 0.3f);
    }
    if (!isOn)
    {
        centerRend.material.color = new Color(0, 255, 0, 0.3f);
    }
    middleRend.material.color = new Color(255, 255, 255, 0.3f);
    outerRend.material.color = new Color(255, 0, 0, 0.3f);

}

// Update is called once per frame
void Update()
{

}

public void FadeMe()
{
    StartCoroutine(DoFade());
}

IEnumerator DoFade()
{
    CanvasGroup canvasGroup = GetComponentInChildren<CanvasGroup>();
    while (canvasGroup.alpha > 0)
    {
        canvasGroup.alpha -= Time.deltaTime;
        yield return null;
    }
    canvasGroup.interactable = false;
}

}

Anyone see what I am doing wrong?

Answers

Sign In or Register to comment.