Unity freezes when changing GUI.Color.a

Hi, I’m working on a school project and I trying to make a DMC devil trigger style UI, you know those circular things then fade away when you activate devil trigger in dmc. I’ve tried using this method where there is a controller script for the meter, and there is a GUI script for each of the circles itself. I’ve encountered this problem where unity always freezes when I set enrage to true. I would like to ask for a solution to this problem if there is a problem in my script, or if there is a better way to accomplish this. Thanks in advance!

This is my rageMeterController Script:

var rageMeterPrefab: GameObject;	//the prefab to instantiate
var rageMeter: RageMeterScript[];	//the array to grab all scripts from the rage meter game objects
var rageCount: int;	//the number of circles
var enraged: boolean;	//is the player in "rage" mood?
var empty: boolean;	//is the current circle empty?

function Start () 
{
	rageCount = GameControl.gameController.pRage;	//grabs the number of circles from the Game Controller
	rageMeter = new RageMeterScript[rageCount];	//creates a new array according to the rageCount variable
	for(var i: int = 0; i < rageCount; i++)
	{
		var rage = Instantiate(rageMeterPrefab, transform.position, Quaternion.identity);	//instantiates the prefab to display the circle
		rage.transform.parent = gameObject.transform;	//parents the circle to this game object
		rageMeter *= rageMeterPrefab.GetComponent(RageMeterScript);	//assigns the script of each instantiated game object to a position in the array*

_ rageMeter*.rageCount = i; //gives each circle its number to change its position by the offset*_
* }*
}

function OnGUI()
{

* if(GUI.Button(Rect(Screen.width/2 - 50, Screen.height/2 - 50, 100, 100), “enrage”)) //tempo button to enrage*
* {*
* enraged = !enraged; //enrage!!!*
* }*
* if(enraged)*
* {*
* //supposedly, starting at the last circle, check if it’s empty. If it isn’t, decrease its alpha. If it is, move to the next circle.*
* for(var i: int = rageCount - 1; i > 0;)*
* {*
_ empty = rageMeter*.empty;
if(empty)
i–;*_

* while(!empty)*
_ rageMeter*.decreaseAlpha();*_

* }*
* } *
}
This is my rageMeter Script:
var rageCount: int; //number of circles
var alpha: float; //alpha for the color
var offSet: float; //offset for the display of the circle
var displayTexture: Texture2D; //the Texture to display
var empty: boolean; //is the circle empty
private var guiColor: Color; //to contain the guicolor

function Start ()
{
* alpha = 1; //sets alpha to 1*
}

function OnGUI()
{
* //sets the GUI color to the variable*
* GUI.color = guiColor;*
* //Creates the circle with offset*
_ GUI.DrawTexture(Rect (Screen.width/2 + 50 + (rageCount* offSet), Screen.height - 35, 25, 25), displayTexture, ScaleMode.StretchToFill, true, 0);
}_

//this function decreases alpha when the player is in “rage” mode
function decreaseAlpha()
{
_ alpha -= 0.1 Time.deltaTime;
}*_

function Update ()
{
* Mathf.Clamp(alpha, 0, 1); //clamps alpha to 0 and 1*
* guiColor.a = alpha; //sets the a value of the color variable to alpha*
* if(alpha > 0) *
* empty = false; //sets empty to false when alpha is more than 0;*

* else if(alpha == 0)*
* empty = true; //sets empty to true when alpha is 0;*

_ //alpha -= 0.1 Time.deltaTime;
}*_

Your problem is here:

 while(!empty)
       rageMeter*.decreaseAlpha();*

You don’t get the new value of empty within the loop, so this code will hand Unity. One fix to the hang is:
while(!empty) {
rageMeter*.decreaseAlpha();*
empty = rageMeter*.empty;*
}
But that doesn’t fix the script. In particular this logic will cause the rageMeter to decrease it alpha all within a single frame, which I don’t believe is what you want. I wonder if just leaving out the while() on line 36 won’t get you what you want.