Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

need help w/ video player script

Discussion in 'Scripting' started by avenn503, Dec 8, 2018.

  1. avenn503


    Dec 8, 2018
    i want to create a script that plays video clip when i collide with an object, here is what i have:
    Code (JavaScript):
    1. public class PlayVideo : MonoBehaviour
    2. {
    3.     public GameObject videoPlayer;
    4.     public int timeToStop;
    6.     void Start()
    7.     {
    8.         videoPlayer.SetActive(false);
    9.     }
    11.     void OnTriggerEnter(Collider player)
    12.     {
    13.         if (player.gameObject.tag == "Player")
    14.         {
    15.             videoPlayer.SetActive(true);
    16.             Destroy(videoPlayer, timeToStop);
    17.         }
    18.     }
    19. }
    it doesnt seem to work and i couldnt figure it out what is wrong. any help?
    @LurkingNinjaDev i want to destroy the video clip after it finish playing so it doesnt stay on the screen for the entire time.
    Last edited: Dec 8, 2018
  2. Lurking-Ninja


    Jan 20, 2015
    Put your code in code tags in your post please. Hit Edit link on the bottom of your post, you can find the code button in the toolbar while you're editing it.

    As for your problem: Why are you destroying your videoPlayer object? What is the value of the timeToStop?