Hello,
I am hoping someone might be able to give me some insight into where I might be going wrong here.
The basic premise is that in a mobile VR experience I am trying to use gaze input to trigger actions, very simple actions that fade-in or fade-out panels etc.
This is a simple process with 2 separate buttons, but I am trying to experiment with using a single button to change the state of the panel, using if statements to determine how it should react dependant upon the current state.
I am however missing something, and as I am reasonably new to programming I would be very appreciative if anyone can help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroupFaderState : MonoBehaviour {
public CanvasGroup uiElement;
bool _panelActive;
private void Start()
{
uiElement.alpha = 0;
_panelActive = false;
}
public void ChangeState()
{
if (_panelActive = false)
{
StartCoroutine(FadeCanvasGroup(uiElement, uiElement.alpha, 1));
}
else if (_panelActive = true)
{
StartCoroutine(FadeCanvasGroup(uiElement, uiElement.alpha, 0));
}
else return;
}
public IEnumerator FadeCanvasGroup(CanvasGroup canvasGroup, float start, float end, float lerpTime = 0.5f)
{
float _timeStartedLerp = Time.time;
float timeSinceStarted = Time.time - _timeStartedLerp;
float percentageComplete = timeSinceStarted / lerpTime;
while(true)
{
timeSinceStarted = Time.time - _timeStartedLerp;
percentageComplete = timeSinceStarted / lerpTime;
float currentValue = Mathf.Lerp(start, end, percentageComplete);
canvasGroup.alpha = currentValue;
if (percentageComplete >= 1) break;
yield return new WaitForEndOfFrame();
}
print("done");
}
}