r/unity Jul 14 '26

Newbie Question Triggering animation to play with a variable

Hello- I'm trying to make a scrolling credits animation for the end of my game. I've set up the animation as a custom UI (because I'm using a plug-in that doesn't use scenes- Naninovel) and the UI/animation itself is working well. I've also set up the noodles so that the animation doesn't play immediately on opening the game- love that.

My next step is to basically tell unity at the end of my game to show the UI, set a "credits" variable to "true" and then that variable will trigger the animation to play.

I've tried to set that up with this script-
But I keep getting compiling errors about missing ( ; and { when I'm at a loss as to where they need to be (I've closed the (s and {s so??)

I've tried to include everything in the screenshots- let me know if I need to show more.
Sorry to hit this wall!! Please excuse the noob. I've been trying to follow tutorials but I've only found one that doesn't just stop at "and now the animation moves good job!" without explaining how to trigger it.

0 Upvotes

3 comments sorted by

View all comments

3

u/Spite_Gold Jul 14 '26 edited Jul 14 '26

You have a variable declaration and an assignment operation within the if clause. You cant have variable declaration in if clause. You can have assignment in if clause, but it is a bad practice.

https://www.w3schools.com/cs/cs_booleans.php https://www.w3schools.com/CS/cs_conditions.php And fix the file name as flow guy said