<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: twitched</title>
    <description>The latest articles on DEV Community by twitched (@twitched_6016c48959c7d53e).</description>
    <link>https://dev.to/twitched_6016c48959c7d53e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4202472%2Fea6f41a7-7519-4d87-bbc2-2a2b5d4042e1.png</url>
      <title>DEV Community: twitched</title>
      <link>https://dev.to/twitched_6016c48959c7d53e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/twitched_6016c48959c7d53e"/>
    <language>en</language>
    <item>
      <title>Audio-Reactive UI in Unity UI Toolkit: Fire, Lasers and Rain That Follow the Music</title>
      <dc:creator>twitched</dc:creator>
      <pubDate>Fri, 23 Oct 2026 11:36:21 +0000</pubDate>
      <link>https://dev.to/twitched_6016c48959c7d53e/audio-reactive-ui-in-unity-ui-toolkit-fire-lasers-and-rain-that-follow-the-music-13d4</link>
      <guid>https://dev.to/twitched_6016c48959c7d53e/audio-reactive-ui-in-unity-ui-toolkit-fire-lasers-and-rain-that-follow-the-music-13d4</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6ek65sbvhsxw3w6l30h7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6ek65sbvhsxw3w6l30h7.gif" alt="A music player switching songs: flames, then neon lasers, then rain re-theme the whole screen" width="560" height="315"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Switching the track re-themes the whole screen in one tween.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I wanted a music player screen where the whole room follows the song. It has three tracks, and each one is a different genre: metal brings fire, synthwave brings lasers and a neon grid, lo-fi brings rain on the glass. Loud passages make the fire roar and the rain pour, and every beat lands as a surge, a flash or a gust. You can grab the record and scratch it, and pausing freezes every effect mid-air.&lt;/p&gt;

&lt;p&gt;It's built in Unity's UI Toolkit, the newer UI system that works like HTML and CSS (UXML for layout, USS for styles), and every animation is a tween (an animation from one value to another over time) from Cascade, a UI Toolkit tween library I make. You can play it in your browser here (click once for sound): &lt;a href="https://twitchedd.itch.io/cascade-audio-studio" rel="noopener noreferrer"&gt;https://twitchedd.itch.io/cascade-audio-studio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how it came together, including the parts that didn't work the first time.&lt;/p&gt;
&lt;h3&gt;
  
  
  One tween changes the whole room
&lt;/h3&gt;

&lt;p&gt;The starting point was an older version of the screen with a single look. For this one I redesigned it in&lt;br&gt;
Figma with three genres side by side. Each has its own colours, title font, corner shapes and spectrum style&lt;br&gt;
(spikes for metal, neon bars for synthwave, soft dots for lo-fi).&lt;/p&gt;

&lt;p&gt;To avoid twenty animations landing at slightly different times, everything follows one &lt;code&gt;Value&lt;/code&gt; tween from 0&lt;br&gt;
to 1. Every drawn part reads the same number on each frame and blends&lt;br&gt;
from the old genre to the new one: the glows, the spectrum ring, the waveform, the meters, the corner radii.&lt;br&gt;
Halfway through, the ring shrinks to nothing, switches shape and grows back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;morph&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Frame&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InOutCubic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switching genre again mid-morph just cancels the old tween and starts from wherever the room is, so you can&lt;br&gt;
mash the next button and it never snaps.&lt;/p&gt;
&lt;h3&gt;
  
  
  Building the weather
&lt;/h3&gt;

&lt;p&gt;Each genre has its own effects, and every one of them is a looping tween. The motion itself is all tweens; only&lt;br&gt;
the music measurements update every frame.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fire took two tries.&lt;/strong&gt; The first flames were flat shapes, and when they overlapped they stacked like&lt;br&gt;
paper cutouts. The second version draws each flame as a soft gradient (white-hot at the base, orange in the&lt;br&gt;
body, red at the tip, fading out at the edges), so overlapping flames blend into one fire. It's set in three&lt;br&gt;
rows: tall dark-red flames behind the panels, an orange row in front, and a short white-hot row along the&lt;br&gt;
bottom. Each flame runs three loops of different lengths: one bends it, one stretches it, one flickers it.&lt;br&gt;
Because the lengths never line up, the fire never repeats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nf"&gt;Track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tongue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;Mathf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PI&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.9f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1.8f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tongue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Phase&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LoopMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nf"&gt;Track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tongue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;ScaleTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.06f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1.2f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.18f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.34f&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;From&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.82f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.94f&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;Loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LoopMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PingPong&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nf"&gt;Track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tongue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Fade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.65f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.85f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.12f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.28f&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;From&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1f&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LoopMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PingPong&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The rain was too quiet.&lt;/strong&gt; The first version was thin and faint, and against the dark background you could&lt;br&gt;
barely tell it was raining. Now there are two depths: about 120 thin, faint drops in the distance and 40&lt;br&gt;
brighter, thicker ones close to the glass that fall almost twice as fast. Each drop fades from an invisible&lt;br&gt;
tail to a bright head, so it reads as a falling streak, and small splash rings pop along the bottom where&lt;br&gt;
the rain lands.&lt;/p&gt;

&lt;p&gt;The lasers are a ping-pong rotate, the grid floor is a looping &lt;code&gt;Value&lt;/code&gt;, and the stars twinkle on fades.&lt;/p&gt;
&lt;h3&gt;
  
  
  Connecting it to the music
&lt;/h3&gt;

&lt;p&gt;The songs are real audio, so the room can react to what's actually playing. Each frame the app reads the&lt;br&gt;
spectrum, folds it into bands and draws the ring from them. Two signals come out of that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Beats.&lt;/strong&gt; When the bass jumps well above its recent average, that's a beat. Each genre answers in its own
way: the fire surges, the lasers flash, the rain gusts sideways and splashes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loudness.&lt;/strong&gt; A level that rises fast and falls slowly. Each genre scales its effects with it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;genre&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scale&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.35f&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.95f&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;energy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1f&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the fire roars&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;beam&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lasers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;beam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Energy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0.1f&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.8f&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;energy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;// lasers brighten&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;SetRainDensity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;energy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                    &lt;span class="c1"&gt;// drizzle to downpour&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A loud passage makes the fire roar up from the bottom edge, and a quiet one settles it into embers. The rain&lt;br&gt;
is my favourite: every drop has its own loudness threshold, so a quiet intro is a drizzle of distant drops,&lt;br&gt;
more join as the song builds, and the fast close streaks only come in on the loud parts.&lt;/p&gt;

&lt;p&gt;The catch with two signals is that they can fight. If the beat and the loudness both write the fire's height,&lt;br&gt;
a beat lifts it and the loudness pulls it straight back down. So they get separate jobs: loudness sets the&lt;br&gt;
fire's height (its scale), and the beat surge is a quick &lt;code&gt;MoveY&lt;/code&gt; that lands on top of it. For the rain, the gust is a &lt;code&gt;Nudge&lt;/code&gt;, which is additive, so it pushes the rain sideways without&lt;br&gt;
fighting the loops that make it fall.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;flames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;MoveY&lt;/span&gt;&lt;span class="p"&gt;(-&lt;/span&gt;&lt;span class="m"&gt;22f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.07f&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OutQuad&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Then&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;MoveY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.45f&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OutCubic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;rainLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Nudge&lt;/span&gt;&lt;span class="p"&gt;(-&lt;/span&gt;&lt;span class="m"&gt;6f&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="m"&gt;14f&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;energy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.4f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Controlling it live
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fge9so55vfz2aww6zjmy7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fge9so55vfz2aww6zjmy7.gif" alt="Pausing the music freezes the flames, embers and rain mid-air" width="560" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pause freezes the world.&lt;/strong&gt; I keep the handle of every effect loop. Pausing the music calls &lt;code&gt;Pause()&lt;/code&gt; on all&lt;br&gt;
of them, so the flames, embers, lasers and rain stop exactly where they are, mid-air. Play carries on from&lt;br&gt;
that frame.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;PauseEffects&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fxTweens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Pause&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ResumeEffects&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fxTweens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Resume&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The record behaves like a turntable.&lt;/strong&gt; My first spin was a looping rotation, and you could see it: every lap&lt;br&gt;
restarted, so the speed hiccuped slightly once per turn. I replaced it with a motor. The record has one speed,&lt;br&gt;
every frame turns it by that speed, and starting, braking and recovering after a scratch are all &lt;code&gt;Value&lt;/code&gt;&lt;br&gt;
tweens on that one number. At full speed nothing is tweening, so the spin is perfectly steady. The music's&lt;br&gt;
pitch follows the speed, so the song slides up as the platter starts and down as it brakes, like real vinyl.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SetMotor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EaseFunction&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;motor&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;Cancel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;motor&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vinyl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Animate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spinSpeed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;spinSpeed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;SetMotor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NormalSpin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.9f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InOutSine&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// play: spin up to 33⅓&lt;/span&gt;
&lt;span class="nf"&gt;SetMotor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1.4f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Ease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OutQuad&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;             &lt;span class="c1"&gt;// pause: the brake&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknfw8qwam3c8jcz96iyl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknfw8qwam3c8jcz96iyl.gif" alt="A cursor scratches the spinning record back and forth, then lets it spin back up" width="560" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can scratch it.&lt;/strong&gt; Grab the record and the music stops dead, like a hand on vinyl. Drag it and the sound&lt;br&gt;
follows your hand. Let go and it keeps the speed of your flick, then the motor eases it back to 33⅓.&lt;/p&gt;

&lt;p&gt;The first version lagged behind the mouse, and it took a while to see why. I was reading the record's angle&lt;br&gt;
back from Unity's resolved style, which is one frame behind whatever you just wrote, so every drag step&lt;br&gt;
started from a stale angle. Now the angle lives in a variable and the record turns on the move event itself.&lt;br&gt;
I also moved the speed measurement to once per frame, so when your hand stops, the sound stops straight away&lt;br&gt;
instead of playing the last speed until the next mouse move.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rest is for poking at.&lt;/strong&gt; Drag the waveform to seek. Drag the mixer faders, and double-click one to spring&lt;br&gt;
it home with a little overshoot. Tap the reaction buttons fast and it builds a combo: bigger bursts, a&lt;br&gt;
springing x2, x3, x4, and the room answers harder each time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting it into a browser
&lt;/h3&gt;

&lt;p&gt;Unity's web player has four limits that needed workarounds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can't read the audio spectrum, so on the web the music is real but the ring and the beats follow a simulated signal at each song's tempo.&lt;/li&gt;
&lt;li&gt;It can't play sound backwards, so backwards scratches go silent.&lt;/li&gt;
&lt;li&gt;It doesn't run the mixer's filters, so only the LEVEL fader changes what you hear.&lt;/li&gt;
&lt;li&gt;It holds all audio until the first click, so the "song ended, play the next one" check only counts near the end of a song.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of the animation code changed, because Cascade runs on UI Toolkit's own scheduler.&lt;/p&gt;

&lt;h3&gt;
  
  
  Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reduce the music to two signals (beats and a loudness level) and let every effect read them. It keeps each effect's code tiny and makes adding a genre cheap.&lt;/li&gt;
&lt;li&gt;Give each signal its own property, so a beat kick lands on top of the loudness level instead of fighting it.&lt;/li&gt;
&lt;li&gt;Keep the handles of looping animations. Pausing them is what makes "freeze the world" a one-liner.&lt;/li&gt;
&lt;li&gt;When something lags behind the mouse by a frame, check whether you're reading back a value the engine resolves later.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Try it
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Play it in the browser: &lt;a href="https://twitchedd.itch.io/cascade-audio-studio" rel="noopener noreferrer"&gt;https://twitchedd.itch.io/cascade-audio-studio&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The original devlog on itch: &lt;a href="https://twitchedd.itch.io/cascade-audio-studio/devlog/1711007/making-a-music-player-ui-that-plays-along-with-the-song" rel="noopener noreferrer"&gt;https://twitchedd.itch.io/cascade-audio-studio/devlog/1711007/making-a-music-player-ui-that-plays-along-with-the-song&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cascade Lite, the free (MIT) tier; everything here except the springs and staggered bursts works with it: &lt;a href="https://assetstore.unity.com/packages/slug/394764" rel="noopener noreferrer"&gt;https://assetstore.unity.com/packages/slug/394764&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sample itself comes to Cascade in a future update.&lt;/p&gt;

&lt;p&gt;What would you map to the music for a fourth genre?&lt;/p&gt;

</description>
      <category>unity3d</category>
      <category>gamedev</category>
      <category>csharp</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
