I am new to coding and unity, I have looked on the forums and have found similar issues, but none of the fixes I have tried(so far) have worked. What I am trying to accomplish is when I click on an object, I want to have that object fade. When I select it again, I want it to show up normally (alpha 255). Here is the c# code I am using:
public void OnPointerDown (PointerEventData eventData)
{
Debug.Log (“on pointer down”);
GameObject gameState = GameObject.Find(“Game State”);
if(eventData.button != PointerEventData.InputButton.Left){
return;
}
if(gameState.GetComponent<gameState>().gameStage == 1){
if(gameState.GetComponent<gameState>().selected <2 &&
cardSelected == false){
Debug.Log (this.transform.name +" Selected");
cardSelected = true;
color.a = 100f;
this.GetComponent<Image>().color = color;
Debug.Log (this.GetComponent<Image>().color.a);
if(selectorIndex<1){
gameState.GetComponent<gameState>().selected++;
selectorIndex++;
}
}else{
Debug.Log (this.transform.name +" Deselected");
cardSelected = false;
if(gameState.GetComponent<gameState>().selected>0){
Debug.Log ("Normal alpha applied");
color.a = 255f;
this.GetComponent<Image>().color = color;
Debug.Log (this.GetComponent<Image>().color.a);
if(selectorIndex<0){
gameState.GetComponent<gameState>().selected--;
selectorIndex--;
}
}
}
}
}
When debugging I can tell the alpha number has changed, but it doesn’t appear to apply to the object in the game window… I can only guess I am not properly applying the value somehow, or missing a setting somewhere. There isn’t any code that affects the color of the object except for this. Anything helps thanks.