Hello,
After lots of googling and attempts, I’ve hit a wall. I am unsure of how to make an extension method for AudioSource.PlayClipAtPoint.
My goal is to simply add a pitch variable (I would love to put in a simple random range to mix it up a bit).
I am successfully able to make my own extension PlayClipAtPointWithPitch, that modifies an existing audioSource.
public static AudioSource PlayClipAtPointWithPitch(this AudioSource audioSource, AudioClip clip, Vector3 position, float volume, float pitch)
{
//Code here...
return audioSource;
}
//Usage Example:
myAs.PlayClipAtPointWithPitch(hitClip, transform.position, 1.0f, 0.75f);
However, this isn’t the same functionality as AudioSource.PlayClipAtPoint().
I would like to call it, and have it create the AudioSource itself, and apply the settings from the given params.
The syntaxes I’ve tried do not visibly add any extensions to PlayClipAtPoint that I can see. I know it is very likely that I am missing some very simple syntax.
public static void PlayClipAtPoint(this AudioSource audioSource, AudioClip clip, Vector3 position, float volume, float pitch)
{
//Code here...
}
Desired usage example: AudioSource.PlayClipAtPoint(hitClip, transform.position, 1.0f, 0.75f);
I am unsure of what “this” in this circumstance is doing, because I am not calling this on any pre-existing object. All the similar examples I’ve found are a more traditional extension like my working first bit of code, or have left me scratching my head.
I know that I can do something similar with a regular static method that I call from file to file, but I would really like to understand how to do this properly.
Any help or advice would be much appreciated. Thanks!