I am new in unity developement,I want to develope application which can add piano sound to song.
How to achieve this functionality.
Please help me!
Two approaches, the memory management friendly way or the Garbage collector friendly way.
GC friendly means you need to have as many audio source as you want simultaneous sounds. Considering it is for piano, you should not get more than 10 notes at a time, considering you do play with your fingers.
So you would have an object with 10 AudioSource components and each could be assign to a particular finger. For instance, you can assign priorities to each of them so you can find which is what. Then looking at it you can assign the note and play it.
In this case you have all components in memory at all time but no GC is called.
Other way is using
Each time you call the method a new AudioSource object is created and lives for the duration of the sound, then it is finally destroyed automatically. It is way easier with code since it is only one line but then if you play a symphony, there will be thousands of note, and that could end up with a call to the GC.
Your choice.