Search Unity

Movie texture plays in scene and game view only

Discussion in '2D' started by Ksong33, May 17, 2016.

  1. Ksong33

    Ksong33

    Joined:
    May 17, 2016
    Posts:
    2
    I am new to C# and Unity. So far I have built a 2D platformer and I am almost finished with my game.This is my first time posting to the forum and I have tried looking for a similar question like mine. If I am missing a detail please let me know. I am trying to put up as much info as I can think of that will help.

    I have two movie texture codes. One is the introduction scene that plays when the player first starts the game. In game view, scene and game view, and in the build, this works perfectly! However, with my second code I have a trigger that sets off the movie texture at the end of each level. All I did was changed the introduction code to start with a trigger. The problem is that with the triggered code the movie texture will only play when I have both the scene view and game view open. When I maximize the game view or make a build, the movie texture will not trigger at all. (The inspector is set up the same way for both intro and triggered movie textures.)

    Introduction movie texture code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5.  
    6. [RequireComponent (typeof(AudioSource))] // allows you to play audio with movie texture
    7.  
    8. public class IntroCam : MonoBehaviour {
    9.     public MovieTexture movie;
    10.     public new AudioSource audio;
    11.  
    12.     public string levelToLoad;
    13.  
    14.     void Start()
    15.     {
    16.         GetComponent<RawImage>().texture = movie as MovieTexture;
    17.         audio = GetComponent<AudioSource>();
    18.         audio.clip = movie.audioClip;
    19.         movie.Play();
    20.         audio.Play();
    21.  
    22.         Invoke("nextscene", 5);
    23.     }
    24.  
    25.     void nextscene()
    26.     {
    27.         SceneManager.LoadScene(levelToLoad);
    28.     }
    29.  
    30. }


    Triggered movie texture code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5.  
    6. [RequireComponent(typeof(AudioSource))]
    7.  
    8. public class IntroCamV02 : MonoBehaviour {
    9.     public MovieTexture movie;
    10.     private new AudioSource audio;
    11.  
    12.     public string levelToLoad;
    13.     void Start()
    14.     {
    15.             GetComponent<RawImage>().texture = movie as MovieTexture;
    16.             audio = GetComponent<AudioSource>();
    17.             audio.clip = movie.audioClip;
    18.     }
    19.     void OnTriggerEnter2D(Collider2D other)
    20.     {
    21.         //((MovieTexture)GetComponent<Renderer>().material.mainTexture).Play();
    22.         movie.Play();
    23.         audio.Play();
    24.        
    25.         Invoke("nextscene", 10);
    26.     }
    27.  
    28.     void nextscene()
    29.     {
    30.         SceneManager.LoadScene(levelToLoad);
    31.     }
    32. }
    Any help would be greatly appreciated. :)
     
  2. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    You code looks okay.

    Try making a Debug.Log in OnTriggerEnter2D and see if it gets called at all - my guess is that it's never invoked and you might have to go through the scene and check that the 2d colliders are working as they should.

    Also, bear in mind that you're are maybe loading a scene as playing a movie at the same time? Maybe the Movieplayer might be destroyed if you dont make sure that the Intromovie is flagged as "DontDestroyOnLoad" in Awake.
     
  3. Ksong33

    Ksong33

    Joined:
    May 17, 2016
    Posts:
    2
    Thank you~ I can't believe that I didn't think before to add a debug log. As you mentioned, when the game and scene view are both opened the trigger was invoked. However, when I had the game view maximized it wasn't being invoked. I am now in the process of working with the colliders...there has to be something that I am missing.