I hope my question is not duplicate; I have a problem in unity. I write a class for transparency(fade in/fade out loop) of object.that's worked right. I put two button in scene.They are in canvas place. after run ,Even though I have written a command for transparency one object in canvas, all the things inside go to transparency(fade in and fade out loop). I do n't know. please help.
myclass
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
using System;
public class Transparent : MonoBehaviour {
private float duration = .7f;
public float waitTime;
IEnumerator co2;
// Update is called once per frame void
public void start_tranparecncy()
{
this.co2=this.blink();
this.StartCoroutine (this.co2);
}
IEnumerator blink() {
//Color textureColor = this.transform.GetComponent<SpriteRenderer> ().material.color;
Color textureColor = this.transform.GetComponent<Image>().material.color;
//textureColor.a = Mathf.PingPong(Time.time, duration) / duration;
//this.GetComponent<SpriteRenderer>().material.color = textureColor;
while (true) { // this could also be a condition indicating "alive or dead"
// we scale all axis, so they will have the same value,
// so we can work with a float instead of comparing vectors
textureColor.a=Mathf.PingPong (Time.time, duration) / duration;
this.transform.transform.GetComponent<Image> ().material.color = textureColor;
// reset the timer
yield return new WaitForSeconds (waitTime);
}
//end of if(this.transform.childCount =0)
}
void stop_Transparency ()
{
this.StopCoroutine (this.co2);
}
}