Quantcast
Channel: Questions in topic: "vs"
Viewing all articles
Browse latest Browse all 110

Which is faster: AudioClips or GameObjects with Audio attached?

$
0
0
Hello, I've got a gun script, the prefab has not an AudioSource attached, every time I hit "Fire1" it shoots, and instantiate a gameobject with an audio clip attached to it. It works fine. This is the point in question: var holdSound : GameObject if (Input.GetButton("Fire1")) { //Shoot part... if (bulletSound) holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation); } The question is: It would be more convenient for my code optimization to attach an AudioSource to the gun and play AudioClips directly without Instantiating gameobjects everytime i hit fire? For example: if (Input.GetButtonDown("Fire1")) { //Shoot Part... audio.PlayOneShot(bulletSound); } What's the difference between both methods? Thanks.

Viewing all articles
Browse latest Browse all 110

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>