i have these 2 methods that have the same behavior and i want to make a single function Opacador
that can change the color as much for the text as for the image. The problem is that i cannot replace the signature for IEnumerator Opacador (float ... ,Gameobject objeto)
because Gameobject can’t do Color colorActual = objeto.color
.
I also tried Color colorActual = gameObject.GetComponent<Renderer>().material.color
but this gave me error. is there anything i can do?
IEnumerator Opacador(float timpDeColorado, float aphaFinal, Image objeto) {
//Opacador code
}
IEnumerator Opacador(float timpDeColorado, float aphaFinal, TextMeshProUGUI objecto) {
//OpacadorDeTilulo code
}
this is how you take multiple arguments. Like how Destroy(gameObject) and Destroy(gameObject, time). This means that when Opacador gets called, depending on what arguments you feed it will determine how which IEnumerator gets run.
Alternatively, you could use
IEnumerator Opacador(float timpDeColorado, float aphaFinal, bool useImage, GameObject item) {
//simalarities
if(useImage) {
Image img = item.GetComponent<Image>();
// image only code
}
else {
TextMesPro txt = item.GetComponent<TextMeshPro>();
//TextMeshPro only code
}
}
This could also work. However, it would be worse when you call it. (overcomplicated)