Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question error CS1061

Discussion in 'Audio & Video' started by chen1009839427, May 15, 2023.

  1. chen1009839427

    chen1009839427

    Joined:
    Mar 19, 2023
    Posts:
    3
    I'm making a simple sound player using unity, I follow the tutorial but this problem occurs:Assets\Scripts\SoundManager.cs(14,21): error CS1061: 'AudioSource' does not contain a definition for 'Clip' and no accessible extension method 'Clip' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
    I want to know how to solve it.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SoundManager : MonoBehaviour
    6. {
    7.     public AudioClip[] AudioClips;
    8.     AudioSource audioSource;
    9.     int CurrentTrack = 0;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         audioSource = GetComponent<AudioSource>();
    14.         audioSource.Clip = AudioClips[CurrentTrack];
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.  
    21.     }
    22.  
    23.     void Play()
    24.     {
    25.         audioSource.Play();
    26.     }
    27.  
    28.     void Pause()
    29.     {
    30.         audioSource.Pause();
    31.     }
    32.  
    33.     void Stop ()
    34.     {
    35.         audioSource.Stop();
    36.     }
    37.     void Mute()
    38.     {
    39.         audioSource.mute = true;
    40.     }
    41.  
    42.     void UnMute()
    43.     {
    44.         audioSource.mute = false;
    45.     }
    46.  
    47.     void Next()
    48.     {
    49.         Stop();
    50.         if (CurrentTrack == AudioClips.Length)
    51.              CurrentTrack = 0;
    52.            
    53.         else
    54.              CurrentTrack++;
    55.         audioSource.Clip = AudioClips[CurrentTrack];
    56.         Play();
    57.     }
    58.  
    59.     void Previous()
    60.     {
    61.         Stop();
    62.         if (CurrentTrack == 0)
    63.             CurrentTrack = AudioClips.Length;
    64.  
    65.         else
    66.             CurrentTrack--;
    67.         audioSource.Clip = AudioClips[CurrentTrack];
    68.         Play();
    69.     }
    70. }
    71.  
     
  2. chen1009839427

    chen1009839427

    Joined:
    Mar 19, 2023
    Posts:
    3
    What an idiot I was, problem solved. It took me 3 times to check the code before I realized that I capitalized the "c".
     
  3. sujalchauhan

    sujalchauhan

    Joined:
    May 16, 2023
    Posts:
    1
    class MyClass
    {
    public void DoSomething()
    {
    // Do something here
    }
    }

    class Program
    {
    static void Main(string[] args)
    {
    var myObject = new MyClass();
    myObject.DoSomethingElse(); // This line will cause CS1061 error
    }
    }
    https://nettecky.com/
     
  4. SharonGallo

    SharonGallo

    Joined:
    Jun 14, 2023
    Posts:
    2
    I agreed with you, it is hard to find the problem.
     
    Last edited: Jul 21, 2023
  5. SharonGallo

    SharonGallo

    Joined:
    Jun 14, 2023
    Posts:
    2