Cannot get access to the AudioSource class

So I am building a scene for my VR project, and I want to play footsteps sound whenever my character is moving. I thought this might be a piece of cake, but for some reason I cannot access the AudioSource class in the code for the chraracter movement.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] Transform playerCamera = null;
    [SerializeField] float mouseSensitivity = 10f;
    [SerializeField] bool lockCursor = true;
    AudioSource audioSrc;
    bool isMoving = false;
    public CharacterController contoller;
    public float speed = 6f;
    float cameraAngle = 0f;

    // Start is called at the start
    void Start(){
        if(lockCursor){
            // locks cursor to middle of the screen
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = false;

            audioSrc = GetComponent<AudioSource>();
        }
    }

is there some error message? and the gameobject has audiosource?

and lockcursor is true? as it has getcomponent inside ‘if (lockCursor)’, so if its false then that code doesnt run.

1 Like

Sorry forgot to update. The gameobject did not have an audiosource which caused the issue. Should have checked more thoroughly before I posted my question!