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.
↧