• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 16, 2017 at 05:43 PM by kdkev for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by kdkev · Mar 16, 2017 at 08:23 PM · c#audiosourcemovietexture

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kdkev · Mar 16, 2017 at 08:37 PM 0
Share

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.

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

AudioClip array error 1 Answer

How can we get the current video time for scrubbing? 0 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges