i have 8 empty game objects around camera , want same sounds come points in world. how can playclipatpoint correctly accomplish this. script on audio manager empty game object. want audio come point1-point8 transforms position.
public class audiomanagerscript : monobehaviour { public transform point1; public transform point2; public transform point3; public transform point4; public transform point5; public transform point6; public transform point7; public transform point8; // use initialization public audioclip clip1; public audioclip clip2; public audioclip clip3; public audioclip clip4; public audioclip clip5; public audioclip clip6; public audioclip clip7; public audioclip clip8; public audioclip clip9; public audioclip clip10; public audiosource audio; void start() { invokerepeating("myfunc", 1.0f, 1.0f); audio = getcomponent<audiosource>(); } void myfunc() { audio.playclipatpoint(clip1,point1.transform.position,0.9f); } }
playclipatpoint
static
function of audiosource
class. can't call static functions on instances. should call on type:
audiosource.playclipatpoint(clip1, point1.transform.position, 0.9f);
as sidenote: recommend declare arrays transforms
, audioclips
, populate them in inspector instead of having public field each one. make picking random positions , sounds lot easier (you'd otherwise have put of objects arrays hand lot more work , less flexible).
so replace of field declarations with:
public transform[] points; public audioclip[] clips;
then use index access them.
Comments
Post a Comment