You have a variable to hold an audio clip for the looping animation. It has to be called the same time as the animation and passes the loop audio clip to the little audio-processing function.
2. Add the following line below the line that plays the looping animation
3. Save the script.
4. Click Play and pick the Rock and the LockPlate to make sure the sounds play, whether or not the object has an animation.
To check on the looping functionality, you will have to set up the Flower. It has three states: out-of-scene, 0, wilted, 1, and revived, 2. You added the collider to the Flower parent object to register mouse picks, so that is where you will add the two scripts.
1. Add an Interactor script to the Flower.
The Audio Source and ObjectLookup components are automatically added.
2. Select the Rock and copy its Interactor component in the Inspector.
3. Select the Flower, place the cursor over the Transform component label, and choose Paste
Component Values from the right-click menu.
4. Repeat for the Audio Source.
5. Fill out the Interactor for the Flower, as per the State Management PDF. Especially make sure to load the flower revive animation in its Element 2 animation; check Post Loop; and load the flower idle animation into the Loop Animation, Element 1. The AniObject must be set to None or Flower.
6. Load SynthUp as the Loop Sound FX in Element 1.
7. In the Object Lookup component, set Lookup State 1 to Size 1. Set it as follows: Lookup State 1:
Element 0: default,2
You don't need to have a Lookup State 2, because the flower is no longer pickable in that state.
8. Make sure you set the Size of the Replies arrays to match the Object Lookup arrays.
9. Click Play and pick the flower.
The regular animation plays, reviving the flower, then it immediately goes into its loop animation, and the loop sound effect plays. The sound clip doesn’t loop, because Loop is turned off in the Audio Source component. If you wanted to have it loop, you could add audio.loop = true; right below the ProcessAudio (loopSoundFX[currentState]); line.
As usual, after adding to your code, you will have to check the other objects, to make sure you haven’t broken the original functionality.
10. Pick the Rock, KeyAtRock, and LockPlate to make sure they still work.