what's the shortest way to assign a variable to a local AudioSource in Unity 5.0.1?

hey folks - i’m a bit confused at the deprecation of the ‘audio’ keyword in the API these days in Unity 5.0.1. so instead of something simple like:

audio.Play();

we now have

GetComponent.<AudioSource>().Play();

so what i’d like to do is have one line that assigns an AudioSource variable to a keyword like ‘footstep’, so i can call footstep.Play();

but i cannot get the nomenclature right in a single line. i can of course create a variable and then assign in Start() but i’m teaching non-programmer students and would like the line count to be as minimal as possible. what’s the new method to do this, or are you stuck having to declare it and then assign it separately?

separate question, but still similar - is ‘gameObject’ (the local instance of a GameObject referred to by a script) still functioning or has that been removed as well?

i’d prefer the C# based approach as i want to teach my students from C# examples and not UnityScript any longer.

any assistance appreciated!

I would say, declaring a variable to store the reference to your AudioSource and then assigning reference to your AudioSource to that variable in start as you have stated is the way to go since along with fulfilling your requirement to have a footsteps variable to access it also is efficient.

If you are teaching someone then you can also teach them the importance of caching here. It’s always better to teach good practices from the beginning itself.

Also for your another question, gameObject is still available.