Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Nov 09, 2018 at 09:35 AM by hexagonius for the following reason:

Code is too long and not reduced to the relevant part

avatar image
0
Question by jessentannn · Nov 09, 2018 at 09:19 AM · videoimage target

when image target detected the video is play , but when target lost the sound is still play. pls help.

hi , im ccurrenly using unity to built my project . but stuck at the videoplayer and audio when my image target detected my video player is played ( still what i want ) but when target lost the sound is sstill playing until I deetected my image target again . im trying to using videoplayer.pause but when i do that , my image target that detected picture is lost.

here is my code

 // DefaultTrackableEventHandler
 using UnityEngine;
 using UnityEngine.UI;
 using Vuforia;
 using UnityEngine.Video;
 
 
 public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler
 {
     public AudioSource soundTarget;
     public AudioClip clipTarget;
     
     private AudioSource[] allAudioSources;
     public Transform TextTargetName;
 
     public Transform TextDescription;
 
     public Transform PanelDescription;
 
 
   
 
     public UnityEngine.UI.Image uploadimage;
 
     public string filepath =" Assets / Resources / resources / image ";
     public VideoClip videoClip;
     public Renderer x;
     
     protected TrackableBehaviour mTrackableBehaviour;
 
     private void StopAllAudio()
     {
         allAudioSources = (Object.FindObjectsOfType(typeof(AudioSource)) as AudioSource[]);
         AudioSource[] array = allAudioSources;
         foreach (AudioSource audioSource in array)
         {
             audioSource.Stop();
         }
     }
 
     private void playSound(string ss)
     {
         clipTarget = (AudioClip)Resources.Load(ss);
         soundTarget.clip = clipTarget;
         soundTarget.loop = false;
         soundTarget.playOnAwake = false;
         soundTarget.Play();
     }
 
     protected virtual void Start()
     {
         mTrackableBehaviour = GetComponent<TrackableBehaviour>();
         if ((bool)mTrackableBehaviour)
         {
             mTrackableBehaviour.RegisterTrackableEventHandler(this);
         }
         
         soundTarget = base.gameObject.AddComponent<AudioSource>();
         var videoPlayer = gameObject.AddComponent<VideoPlayer>();
         var audioSource = gameObject.AddComponent<AudioSource>();
         
         videoPlayer.playOnAwake = false;
         videoPlayer.clip = videoClip;
         videoPlayer.renderMode = VideoRenderMode.MaterialOverride;
         videoPlayer.targetMaterialRenderer = x;
         videoPlayer.targetMaterialProperty = "_MainTex";
         videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
         videoPlayer.SetTargetAudioSource(0, audioSource);
         
     }
 
     protected virtual void OnDestroy()
     {
         if ((bool)mTrackableBehaviour)
         {
             mTrackableBehaviour.UnregisterTrackableEventHandler(this);
         }
     }
 
     public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
     {
         if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
         {
             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
             OnTrackingFound();
            
           
         }
         else if (previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NO_POSE)
         {
             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
             OnTrackingLost();
            
             
         }
         else
         {
             OnTrackingLost();
         }
         TextTargetName.gameObject.SetActive(value: false);
         uploadimage.gameObject.SetActive(value: false);
         TextDescription.gameObject.SetActive(value: false);
         PanelDescription.gameObject.SetActive(value: false);
        
 
 
     }
     protected virtual void OnTrackingFound()
     {
         Renderer[] componentsInChildren = GetComponentsInChildren<Renderer>(includeInactive: true);
         Collider[] componentsInChildren2 = GetComponentsInChildren<Collider>(includeInactive: true);
         Canvas[] componentsInChildren3 = GetComponentsInChildren<Canvas>(includeInactive: true);
         Renderer[] array = componentsInChildren;
         foreach (Renderer renderer in array)
         {
             renderer.enabled = true;
         }
         Collider[] array2 = componentsInChildren2;
         foreach (Collider collider in array2)
         {
             collider.enabled = true;
         }
         Canvas[] array3 = componentsInChildren3;
         foreach (Canvas canvas in array3)
         {
             canvas.enabled = true;
         }
         if (mTrackableBehaviour.TrackableName == "itsimc")
         {
             VideoPlayer vp = GetComponent<VideoPlayer>();
             if (vp.isPlaying)
             {
                 vp.Stop();
             }
             else
             {
                 vp.Play();
             }
            
         }
         if (mTrackableBehaviour.TrackableName == "STNK")
         {
             playSound("sound/stnksound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "stnkimg");
         }
         if (mTrackableBehaviour.TrackableName == "HELM")
         {
             playSound("sound/helmsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "helmimg");
         }
         if (mTrackableBehaviour.TrackableName == "SIMCARD")
         {
             playSound("sound/simsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "simcardimg");
         }
         if (mTrackableBehaviour.TrackableName == "JACKET")
         {
             playSound("sound/jacketsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "jacketimg");
         }
         if (mTrackableBehaviour.TrackableName == "SARUNGTANGAN")
         {
             playSound("sound/glovessound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "gloveimg");
         }
         if (mTrackableBehaviour.TrackableName == "SEPATU")
         {
             playSound("sound/shoesosund");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "shoesimg");
         }
         if (mTrackableBehaviour.TrackableName == "PAD")
         {
             playSound("sound/padsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "padimg");
         }
         if (mTrackableBehaviour.TrackableName == "MASKER")
         {
             playSound("sound/maskersound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "maskerimg");
         }
         if (mTrackableBehaviour.TrackableName == "RAINCOAT")
         {
             playSound("sound/coatsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "raincoat");
         }
         if (mTrackableBehaviour.TrackableName == "HANDPHONE")
         {
             playSound("sound/hapesound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "handphoneimg");
         }
         if (mTrackableBehaviour.TrackableName == "RODA")
         {
             playSound("sound/wheelsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "wheelimg");
         }
         if (mTrackableBehaviour.TrackableName == "BENSIN")
         {
             playSound("sound/fuelsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "fuelimg");
         }
         if (mTrackableBehaviour.TrackableName == "SPION")
         {
             playSound("sound/spionsound");
             uploadimage.sprite = Resources.Load<Sprite>(filepath + "spionimg");
         }
      
     }
        
 
     protected virtual void OnTrackingLost()
     {
         
         Renderer[] componentsInChildren = GetComponentsInChildren<Renderer>(includeInactive: true);
         Collider[] componentsInChildren2 = GetComponentsInChildren<Collider>(includeInactive: true);
         Canvas[] componentsInChildren3 = GetComponentsInChildren<Canvas>(includeInactive: true);
         Renderer[] array = componentsInChildren;
         foreach (Renderer renderer in array)
         {
             renderer.enabled = false;
         }
         Collider[] array2 = componentsInChildren2;
         foreach (Collider collider in array2)
         {
             collider.enabled = false;
         }
         Canvas[] array3 = componentsInChildren3;
         foreach (Canvas canvas in array3)
         {
             canvas.enabled = false;
         }
 
        
         StopAllAudio();
     }
     
 }
 

pls help . thanks in advanced.

Comment
Add comment
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

96 People are following this question.

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

Related Questions

Have both canvas' buttons and Vuforia video canvas' button working in the same scene? 0 Answers

Video Plane on Image Target - Replay Button (Beginner level) 0 Answers

VIDEO PLAYER ISSUE - UNITY 2017.4.0f1 - VUFORIA VIDEO DOES NOT PLAY WHEN THE URL (WEBSERVER) IS ASSIGNED VIA A VARIABLE 1 Answer

my AR camera keep blinking or flickering when target image detected , please help 1 Answer

How do I play a full screen video? 4 Answers


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