Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. 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. LurkingNinjaDev


    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?