C# audio.PlayClipAtPoint issue

Hi guys,

Trying to make some sounds and getting an annoying error I can’t figure out.

	public AudioClip Explosion, ScoreSound;

		audio.PlayClipAtPoint(ScoreSound, this.transform.position);

Comes up with error: Static member `UnityEngine.AudioSource.PlayClipAtPoint(UnityEngine.AudioClip, UnityEngine.Vector3)' cannot be accessed with an instance reference, qualify it with a type name instead

Any ideas what it is not liking?

Thanks in advance

http://social.msdn.microsoft.com/Forums/en-US/b73e3918-ca28-424e-88fc-e12da5d592d1/cannot-be-accessed-with-an-instance-reference-qualify-it-with-a-type-name-instead-is-the-error-im?forum=csharplanguage

The documentation is a bug; you should report it.

Thanks for the response Jessy :).

Any ideas on how to use the function? I can get around it by cheating, but it goes against my work ethic lol.

The link explained what a static method is. The documentation says it is a static function. It won’t come up in the autocomplete list for audio, because audio is a reference to an AudioClip. Learn what a static method is, use it as such, and report the documentation as a bug after you understand it.

Did you get the audio problem resolved?

if not, this may help…
I have an Inventory script attached to my player.
In my Inventory script it looks like this…

using UnityEngine;
using System.Collections;

public class Inventory : MonoBehaviour {
	
	public AudioClip Pickup1Sound;
	public AudioClip Pickup2Sound;
	public AudioClip Pickup3Sound;
	public AudioClip Pickup4Sound;
	public AudioClip Pickup5Sound;
	public AudioClip Pickup6Sound;
	public AudioClip Pickup7Sound;
	public AudioClip Pickup8Sound;
	public AudioClip Pickup9Sound;
	public AudioClip Pickup10Sound;
	
	    void SwordCPickup(){
		AudioSource.PlayClipAtPoint(Pickup7Sound, transform.position);
		
     	}
	
		void Start () {
				}
	
	void Update () {
			}			
}

I have another script for my object. I cut out all the other objects so you can read code quickly. I just make a file for pickup of each item and tell them to call whatever"Pickup" here and it plays the audio file I told it to in the code above. I rotate my item, but you don’t have to. Just cut out that part. The public float rotation in the START and the transform.rotate line in the UPDATE.
Code for my SwordC

using UnityEngine;
using System.Collections;

public class SwordC : MonoBehaviour {
public AudioClip Pickup7Sound;	
	
	void Start () {
	
	}
	public float rotationSpeed = 100.0f;
	
	void Update () {
	transform.Rotate(new Vector3(0, rotationSpeed * Time.deltaTime, 0));
   	}
	
	void OnTriggerEnter(Collider col){
		if(col.gameObject.tag == "Player"){
			col.gameObject.SendMessage("SwordCPickup");
			Destroy(gameObject);
		}
	}
	
	
}

hope it helps get you in the correct direction

I have found why this bug its occur.
You need to call the audio source without reference it.

if i use:

private AudioSource myAudio;

on Awake myAudio = GetCompo…

myAudio.PlayClipAtpoint(blablabla);

Then you get the error.
Instead of that, if you use AudioSource.PlayClipAtPoint(blablabla)
Then it works.

That is what it means to be a static method. Do not use the word “the”, here. “The audio source” is terminology which states that you have an instance of the class AudioSource. PlayClipAtPoint belongs to the class AudioSource, not an instance of it.

The documentation got fixed at some point in the last couple of years.