tag:blogger.com,1999:blog-1621202784818412273.post7828660924962785526..comments2023-07-20T09:27:43.634-04:00Comments on Tumbleweed Express Development Blog: Unity C# AudioManager Tutorial - Part 4 (Music, Pausing, & Voice Over)Matthew Mauriellohttp://www.blogger.com/profile/12362338784151038359noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-1621202784818412273.post-43177625306098900452016-08-29T22:42:37.441-04:002016-08-29T22:42:37.441-04:00What about assigning audio clips to audio mixer gr...What about assigning audio clips to audio mixer groups?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1621202784818412273.post-63637650668897037652015-05-18T13:59:13.931-04:002015-05-18T13:59:13.931-04:00That's right. In order to attach the sound to ...That's right. In order to attach the sound to a prefab in unity, you need to make it a public member variable in the c# code. Once you have that, you can just reference the audio clip as the variable from inside the class. If you want to access the clip from another class, you'll need to call GetComponent to get the script with the audio clip variable, and then call the public member variable from that. Example:<br /><br />MyPrefabWithAudioClipScript.GetComponent().MyAudioClipMember<br /><br />I do not have metrics for differences in efficiency between resources.load vs a public variable in unity. I have heard that resources.load is slower. However, my recommendation for optimization in general is as follows:<br /><br />1. Code for readability first, optimize for performance later. It is easier to optimize clean code than to clean optimized code.<br />2. If you're going to spend the time to optimize, spend the time to measure the difference in performance. Speculative optimization is uncertain, but certainly (usually) results in lower quality code (harder to read, harder to maintain, harder to update.)Anonymoushttps://www.blogger.com/profile/05836510108468329453noreply@blogger.comtag:blogger.com,1999:blog-1621202784818412273.post-13387028781453329862015-05-07T14:26:17.555-04:002015-05-07T14:26:17.555-04:00Thanks very much for your reply Ben.
So you jus...Thanks very much for your reply Ben. <br /><br />So you just attach your sounds to objects in unity then you can call them with your methods in any other scripts? <br /><br />Do you still need a getcompnent reference in the other script too?<br /><br />Also which of the two options (objects or resources.load) would you recommend for mobile app in terms of efficiency etc..Anonymoushttps://www.blogger.com/profile/02619520581040797691noreply@blogger.comtag:blogger.com,1999:blog-1621202784818412273.post-24251440525629837302015-05-07T09:54:56.072-04:002015-05-07T09:54:56.072-04:00In the cases we're using, audio clips always e...In the cases we're using, audio clips always exist on a gameobject as public member variables. Once you create the public member variables in the code, the audioclip member will appear in the unity inspector under that game object, and you can populate them with sound files from your hard drive there. So our 'TrainEngine' object will have "public AudioClip Horn' and 'public AudioClip Chugga", and then in the code you can pass these audioclips to the audiomanager.<br />Alternatively, you could load the audio clips directly from the 'Resources' folder using AudioClip mySound = Resources.Load( [path] ). See http://docs.unity3d.com/ScriptReference/Resources.Load.html<br />Anonymoushttps://www.blogger.com/profile/05836510108468329453noreply@blogger.comtag:blogger.com,1999:blog-1621202784818412273.post-6159186083717624202015-05-06T14:42:58.106-04:002015-05-06T14:42:58.106-04:00Any advice on where to put the audio clips before ...Any advice on where to put the audio clips before calling them with the method in this script?Anonymoushttps://www.blogger.com/profile/02619520581040797691noreply@blogger.com