- Home /
Error cs0119 expression denotes a 'type' where a 'method group' was expected (Audio)
Hi, I have JUST started learning how to code in C# and am wondering what might be the problem in this code. Right now, I'm following some online courses and received a couple errors saying that some of the code was outdated. I changed the code to what the console recommended. I am simply trying to have a sound effect play when a bouncy ball collides with the ground.
My error seems to be in line 23
Here's the code:
using UnityEngine;
using System.Collections;
public class CollisionComponent : MonoBehaviour {
public AudioClip collisionSound;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnCollisionEnter(Collision theCollision)
{
if (theCollision.relativeVelocity.magnitude > 10)
{
this.GetComponent<AudioSource>()(collisionSound);
}
}
}
Line 23 was originally supposed to be like this, as shown on my online course:
this.gameObject.audio.PlayOneShot(collisionSound);
Now I get this error message: Error cs0119 expression denotes a 'type' where a 'method group' was expected
I'm sure this is super simple to fix, but I just can't figure it out.
Answer by tanoshimi · Apr 04, 2015 at 07:48 AM
The change from v4 to v5 is that audio
becomes
GetComponent<Audio>()
So that line should be:
this.gameObject.GetComponent<Audio>().PlayOneShot(collisionSound);
I just now changed the code to what you had said and it did actually fix the error that I was talking about. But I'm now getting a new error:
error cs0246 the type or namespace name 'Audio' could not be found. Are you missing a using directive or an assembly reference?
Thanks for answering!
Sorry, my bad - should be:
this.gameObject.GetComponent<AudioSource>().PlayOneShot(collisionSound);
Your answer
Follow this Question
Related Questions
Expression denotes a `type', where a `variable', `value' or `method group' was expected 1 Answer
Expression denotes a `method group', where a `variable', `value' or `type' was expected 1 Answer
how to typecast a method holder in Javascript, like Delegate 1 Answer
Problem with var in C# (Vector3, transform and similiar) 1 Answer
Generic Component Declaration 1 Answer