Search Unity

Audio 'AudioSource' not found in UnityEngine namespace?

Discussion in 'Audio & Video' started by ger89_, Jul 21, 2019.

  1. ger89_

    ger89_

    Joined:
    Jul 16, 2019
    Posts:
    3
    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:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AudioManager : MonoBehaviour
    6. {
    7.     AudioSource audioSource;
    8.     private int counter;
    9.     void Start()
    10.     {
    11.         counter = 0;
    12.         audioSource = GetComponent<AudioSource>();
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.         if (audioSource.Time = 0f)
    18.         {
    19.             counter++;
    20.             Debug.Log("Counter: " + counter);
    21.         }
    22.     }
    23. }
    24.  
    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...
     
    Last edited: Jul 21, 2019
    yty likes this.
  2. Edward666_

    Edward666_

    Joined:
    Sep 21, 2018
    Posts:
    5
    Have the same problem is any solution?