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:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
[RequireComponent (typeof(AudioSource))] // allows you to play audio with movie texture
public class IntroCam : MonoBehaviour {
public MovieTexture movie;
public new AudioSource audio;
public string levelToLoad;
void Start()
{
GetComponent<RawImage>().texture = movie as MovieTexture;
audio = GetComponent<AudioSource>();
audio.clip = movie.audioClip;
movie.Play();
audio.Play();
Invoke("nextscene", 5);
}
void nextscene()
{
SceneManager.LoadScene(levelToLoad);
}
}
!(http://) !(http://)
Triggered movie texture code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(AudioSource))]
public class IntroCamV02 : MonoBehaviour {
public MovieTexture movie;
private new AudioSource audio;
public string levelToLoad;
void Start()
{
GetComponent<RawImage>().texture = movie as MovieTexture;
audio = GetComponent<AudioSource>();
audio.clip = movie.audioClip;
}
void OnTriggerEnter2D(Collider2D other)
{
//((MovieTexture)GetComponent<Renderer>().material.mainTexture).Play();
movie.Play();
audio.Play();
Invoke("nextscene", 10);
}
void nextscene()
{
SceneManager.LoadScene(levelToLoad);
}
}
Any help would be greatly appreciated.