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.