Learn to make cutscenes in unity3d by building a stealth Game.
Objective: challenge Modular Voice Over.
Before Doing this creates another script called VoiceOverTrigger.My project already have long box collider which placed at diferent spot on the floor where I want this voice over to play make sure the box is trugger is set to true.
In the first step, go to the Level_Colliders<VO_Triggers, select all child components and attach VoiceOverTrigger to them.
While keep Selecting child components add the audio Source component to all children and disable loop option, make sure you disable play on awake. Then add their voice-over to each object accordingly.
Go to the VoiceOverTrigger script create an audio source variable and serialize it.
Select all VoiceOver Object and drag and drop audio Source to each one according to the object name
Note: You can choose a different way maybe you can cache them in the start method, in solving a problem there is no wrong way.
Now create on trigger enter method and check if we collide with the player if true call an audio method which is the audio “source. Play()”.
Why I didn't use AudioSource.PlayClipAtPoint to avoid dragging or caching components, I notice when I use the AudioSource.PlayClipAtPoint method the audio is played in a very low and weird way. This method Plays an AudioClip at a given position in world space. But you need to assign the clip on the inspector in every object.
Clarification I found out it is not that method that has a problem I usually play it at any location to make sure the players hear the voice clearly using AudioSource.PlayClipAtPointin,you will need to instantiates that audio at the main camera position, this will solve the issue I was talking about above here is the code “AudioSource.PlayClipAtPoint(clip,Main.camera.transform.position);”
To take the challenge further I have to think what if other players are crazy like me when I was a young boy, just they may want to go back to where Daren started the mission and just explore, and I don't want to play this voiceover more than one time.
To solve this situation, create a bool variable and called it , isVoiceOverPlayedOnce and add another check if isVoiceOverPlayedOnce is false, and if the tag is player. Then set it to true when we play the voice.
See you in the next article