- Home /
The question is answered, right answer was accepted
Audio Source issue with MovieTextures
I have a script to play certain movieTextures attached to gameObjects in the scene when the main camera's raycast is pointing at them and stop when the raycast stops looking at them.
script piece on camera:
if (Physics.Raycast (pointRay, out hit, HitDist)) {
if (isVideo == false) {
if (hit.collider.gameObject.tag == "Video") {
PlayPerson PL = hit.collider.GetComponent<PlayPerson>();
LastHit = hit.collider.gameObject;
print ("lastHit " + LastHit); // returns the last object name correctly
if (PL != null) {
PL.PlayPeep (); // calls the PlayPeep method from PP
}
}
if (hit.collider.gameObject.tag != "Video") { // if the tag of the object is not video
LastHit.GetComponent<Collider>().GetComponent<PlayPerson>().StopPeep(); // Stop the video
}
}
Script piece on PlayPerson:
public void PlayPeep() { // plays movie
movie.Play ();
}
public void StopPeep() { // stops movie
movie.Stop ();
}
This works just fine. Until i attempt to look at a video i have already played. This problem is that the video replays but the AudioSource does not. I have tried a few things on my own but none have bore fruit. Any ideas or possible fixes will be a great help.
Edit: i would also like to add that i am attempting this on the personal version of Unity ver 5.5.0f3
Final Edit: the error has been fixed. A simple addition to the PlayPerson Script to check if the audioSource was playing and play it.
public void PlayPeep() { // plays movie
movie.Play ();
if (isPlaying == false) {
audiS.Play ();
isPlaying = true;
}
}
public void StopPeep() {
movie.Stop ();
if (isPlaying == true) {
audiS.Stop ();
isPlaying = false;
}
}
I also found that having play on awake on at the same time as this sent the video on a high speed play through. Simply unchecking play on awake is helps this fact.
This issue has been fixed. The issue seemed to have been with a separate method calling playPeep method. the method has been updated to
public void PlayPeep() { movie.Play(); if (isPlaying == false){ audioS.Play(); isPlaying = true; }
public void StopPeep(){ movie.Stop(); if(isPlaying == true){ audioS.Stop(); isPlaying = false; }
and along with the play on awake disabled in the inspector allowed the videos and audio clips to play at the correct speed and a proper ti$$anonymous$$g when being looked at and stop when not being looked at. This fixed the replay issue i was original having and the audioPlay speed error that accorded as i was trying this fix.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Video Scrubber Bar & Rewind using MovieTexture? 0 Answers
Delayed Button Sounds 0 Answers