I am trying to set an audio clip with a custom action. Seems like I am not having much luck.
I am getting the following error: Assets/VRWeapon_Playmaker/WeaponShotAudioAction.cs(72,35): error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.AudioClip'. An explicit conversion exists (are you missing a cast?)
The orginal script sets the variable as AudioClip
public AudioClip shotSound;In playmaker, I set my Var as
[ObjectType(typeof(AudioClip))]
public FsmObject gunSound;But that doesnt seem to work.
------
My Full Custom Action
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("VRweapons")]
[Tooltip("Adjust the shot sound for VRweapons script on an object")]
// the class must match the name of the action
// if the action is named missleAction then that should be the name of the class
public class WeaponShotAudioAction : FsmStateAction
{
[RequiredField]
// add the name of your script inside of typeof("yourScriptName"))
[CheckForComponent(typeof(Weapon))]
// this is the game object the script is on
public FsmOwnerDefault gameObject;
[Tooltip("Set audio shot sound.")]
// add the variables you want in your action
[ObjectType(typeof(AudioClip))]
public FsmObject gunSound;
// you can usually leave this alone
public FsmBool everyFrame;
// you are making a custom variable with the scripts type
Weapon theScript;
public override void Reset()
{
//its good practice to set your var to null at start
gameObject = null;
gunSound = null;
everyFrame = false;
}
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
// you are grabbing the script from the game object and storing it in your custom variable type
theScript = go.GetComponent<Weapon>();
if (!everyFrame.Value)
{
DoTheMagic();
Finish();
}
}
public override void OnUpdate()
{
if (everyFrame.Value)
{
DoTheMagic();
}
}
//Name your method here
void DoTheMagic()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
//Playmaker variable to Script
theScript.shotSound = gunSound.Value;
//Note! Playmaker var's need .Value after them or they won't work in some cases
}
}
}