unity3d - Sound doesnt play when object collides with collider/ How to play sound and change scene at the same time - unity -
hello want sound play when gameobject collides collider. checked unity documentation , don't seem understand why not working. have audiosource applied collider.
enter code here public audioclip impact; audiosource audiosource; void start(){ audiosource = getcomponent<audiosource>(); } void oncollisionenter2d(collision2d coll){ if (coll.gameobject.tag == "enemy") { audiosource.playoneshot (impact); application.loadlevel ("win"); } } }
the problem in start function because 's'of start capital
replace this
void start()
with
void start()
this fix null reference exception
Comments
Post a Comment