Yes, I have never worked with Unity’s sound system, I managed to do this:
public class JustAmbience : MonoBehaviour {
public AudioClip backgroundMusic;
void Start() {
audio.PlayOneShot(backgroundMusic);
}
}
But it shouts that it’s deprecated and I should use XYZ instead, so I finished up as:
using UnityEngine;
using System.Collections;
public class JustAmbience : MonoBehaviour {
public AudioClip backgroundMusic;
void Start() {
audio.GetComponent<AudioSource>(backgroundMusic);
}
}
Still exactly same error, and I don’t know how to make it work. I saved file, no slots, just file included.
Errors:
Assets/JustAmbience.cs(7,17): error CS0619: UnityEngine.Component.audio' is obsolete:
Property audio has been deprecated. Use GetComponent() instead. (UnityUpgradable)’
Errors:
Assets/JustAmbience.cs(7,23): error CS0308: The non-generic method `UnityEngine.Component.GetComponent(System.Type)’ cannot be used with the type arguments
But I did!