Hi, I’m trying to make a menu class with a fade function. My problem is that I can’t used coroutines in my class, they just don’t work and I don’t get any errors in the console. I want to be able to write something like this:
myMenu.FadeOut();
or
yield myMenu.FadeOut();
I’m not sure, I’ve tried every combination I can think of but nothing.
this is my class:
static class Menu {
var menu //this is assigned in another part of the class
function FadeOut(){
while (menu.renderer.material.color.a > 0){
menu.renderer.material.color.a -= 0.1;
yield WaitForSeconds(1);
}
}
//I have removed the rest of the functionality since it is irrelevant
}
Is there a way I can do this? Any help would be great thanks!
When adding the script to an object I get an error: Can't add script behaviour Menu. The script class can't be abstract.
– thaiscorpionHow is your class declared inside script?
– ArkaneXI'm not really declaring it, just calling it like this: menu.FadeOut(); I wanted it that way so I could access it easily from any script. This works for me with other classes that havent needed coroutines.
– thaiscorpionAnswer edited.
– ArkaneXOh great that is perfect just what I was looking for thanks!!
– thaiscorpion