iTween AudioTo help

For the life of me I can not get AudioTo or AudioFrom to work. Can someone help me with the code. I’m trying to just have it be at volume 0 for now and will adjust the volume later. This is one of many audio sources on this game object.

iTween.AudioTo(gameObject, {“audiosource”:Music_menu_background, “volume”: 0.0});

I’m getting this error
InvalidCastException: Cannot cast from source type to destination type.
iTween.GenerateAudioToTargets () (at Assets/Standard Assets/iTween.cs:3398)
iTween.GenerateTargets () (at Assets/Standard Assets/iTween.cs:3148)
iTween.TweenStart () (at Assets/Standard Assets/iTween.cs:4583)
iTween+c__Iterator2.MoveNext () (at Assets/Standard Assets/iTween.cs:6540)

Can someone help?

Is Music_menu_background a variable set to the type Audiosource?

Sorry for not being as specific, brain freeze and I"m just learning iTween (but I love it so far).

var Music_menu_background:AudioClip;

I put the audio clip in that variable in the Inspector. And have an audio source on the game object that has the audio clip on it. I am trying to turn the volume down when going between menu’s in the same scene.

Then that bit of code…
iTween.AudioTo(gameObject, {“audiosource”:Music_menu_background, “volume”: 0.0});

… is down under a function when you switch menu’s to change the volume of that clip.

The parameter “audiosource” takes the type AudioSource, but you are supplying a AudioClip.
You need to actually supply the audio source as opposed to the audioclip. So:

public var Music_menu_background:AudioSource;

Then in the inspector drag the gameObject with the audiosource onto the Music_menu_background variable. So if the audiosource is on the camera - drag the camera onto the Music_menu_background variable in the inspector. The iTween function actually changes the volume of the audiosource not the clip itself.

Ahhhhhhhhh… I did not know I could use AudioSource’s as variables. Thanks dude Works perfectly.

No worries glad to help :slight_smile:

The iTween documentation ( iTween for Unity by Bob Berkebile (pixelplacement) ) has a list of properties for each function. Generally when you get an InvalidCastException with iTween it’s because you’re passing the wrong type.