'AudioSource' not found in UnityEngine namespace?

Hello,

I’m trying to use AudioSource through a script and Unity doesn’t seem to find the AudioSource class even though I’m using all the necessary “using” directives. What can the problem be? I even tried with “using UnityEngine.AudioModule” but the same.

Here’s my very simple script that is supposed to count every time the audio clip from the audio source was played:

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

public class AudioManager : MonoBehaviour
{
    AudioSource audioSource;
    private int counter;
    void Start()
    {
        counter = 0;
        audioSource = GetComponent<AudioSource>();
    }

    void Update()
    {
        if (audioSource.Time = 0f)
        {
            counter++;
            Debug.Log("Counter: " + counter);
        }
    }
}

And this is the error that I’m getting:

“Assets\AudioManager.cs(17,25): error CS1061: ‘AudioSource’ does not contain a definition for ‘Time’ and no accessible extension method ‘Time’ accepting a first argument of type ‘AudioSource’ could be found (are you missing a using directive or an assembly reference?)”

My Unity version is 2019.1.10f1

EDIT: Solved, I found out I was writing Time with capital T, also I was using “=” instead of “==” in the if statement…

1 Like

Have the same problem is any solution?