Assign a texture on top of the movie texture

I am trying to assign a texture which will be displayed until my video starts. After video has started texture will be dissapeared. Is there any way of doing this ? Thanks

Check the time taken to start the video , then display the texture and wait for the time using yield or something… after the specific time passed disable the texture and display the video…

You should know the time taken to start the video at first.

Well my video is triggered. I am using something like this;

function OnTriggerEnter(other : Collider) {
	if (other.tag == "Player"){

		if (renderer.material.mainTexture.isPlaying) {
			renderer.material.mainTexture.Pause();
			
		}
		else {
			renderer.material.mainTexture.Play();
			audio.Play();
		}
	}
}

function OnTriggerExit (other : Collider) {
	renderer.material.mainTexture.Pause();
	audio.Pause();
}

You could set the mainTexture of the renderer to your preview texture after Start and in OnTriggerExit.

var videoTexture : Texture;
var previewTexture : Texture;
var isPlaying : Boolean;

function Start()
{
  renderer.material.mainTexture = previewTexture;
  isPlaying  = false;
}

function OnTriggerEnter(other : Collider)
{
  if (other.tag == "Player")
  {
    if (isPlaying)
      StopVideo();
    else
      StartVideo();
  }
}

function OnTriggerExit (other : Collider)
{
  StopVideo();
}

function StopVideo()
{
  renderer.material.mainTexture = previewTexture;
  videoTexture.Pause();
  audio.Pause();
  isPlaying = false;
}

function StartVideo()
{
  renderer.material.mainTexture = videoTexture;
  videoTexture.Play();
  audio.Play();
  isPlaying = true;
}

Hello Mark, I have tried to put your script but I am getting an error :confused:

PlayVideoOnTrigger.js(3,17): BCE0018: The name ‘Boolean’ does not denote a valid type (‘not found’). Did you mean ‘System.Boolean’?

it’s not Boolean , it’s boolean…
replace

to

Something which can take a bool (true or false), I am a C# coder so you should look at the code I gave you as pseudo code :wink:

Ok now I have edited the script a bit. After assigning the video file and the texture, what I can see is only the texture ://

var Texture : Texture;
var movie : MovieTexture;
var isPlaying : boolean;

function Start()
{
  renderer.material.mainTexture = Texture;
  isPlaying  = false;
}

function OnTriggerEnter(other : Collider)
{
  if (other.tag == "Player")
  {
    if (isPlaying)
      StopVideo();
    else
      StartVideo();
  }
}

function OnTriggerExit (other : Collider)
{
  StopVideo();
}

function StopVideo()
{
  renderer.material.mainTexture = Texture;
  movie.Pause();
  audio.Pause();
  isPlaying = false;
}

function StartVideo()
{
  renderer.material.mainTexture = movie;
  movie.Play();
  audio.Play();
  isPlaying = true;
}

and getting an error message like this:

UnassignedReferenceException: The variable movie of ‘PlayVideoOnTrigger’ has not been assigned.
You probably need to assign the movie variable of the PlayVideoOnTrigger script in the inspector.
UnityEngine.MovieTexture.Play () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/Graphics.cs:3107)
PlayVideoOnTrigger.StartVideo () (at Assets/MediaCityProject/MCScripts/VideoScript/PlayVideoOnTrigger.js:38)
PlayVideoOnTrigger.OnTriggerEnter (UnityEngine.Collider other) (at Assets/MediaCityProject/MCScripts/VideoScript/PlayVideoOnTrigger.js:18)

Sounds like the variable movie of ‘PlayVideoOnTrigger’ has not been assigned. You probably need to assign the movie variable of the PlayVideoOnTrigger script in the inspector.

The error message says everything you need :slight_smile:

That’s true but I didn’t get what do I need to do exactly :confused:

Here’s a current screenshot:

Strange, did you hit Start to receive the error or does the error occour inside the EditorMode (Stopped)?

Yes thats really strange and I do not have any ideas :frowning:
Error occurs inside the game - when my player triggered with the video object(plane object)

Could you add this right after the StartVideo method head?

print(movie == null ? "Movie is null" : "Movie is not null");

and then tell me what the console windows says after provoking the crash?

Right I have been able to solve the problem :slight_smile: Thanks a lot but now my old video trigger method is not working so I am trying to add a cube object for each video plane but I am not sure how these cube objects will trigger my actual video to start or stop

Do u have any idea for doing something like that ?

What exaclty is not working anymore?

I was using seperate cube objects in front of each video plane with same video and sound files but no mesh renderer for triggering the video planes but this method is not working anymore.

So I tought may be I can put seperate cube objects for each video plane and somehow link each cube object with the video files. Like the video will start when my player gets inside the cube object / stop when my player is out of it.

You could add a childobject to your videoplane, add a BoxCollider to this child and activate the Trigger Checkbox of this BoxCollider.

Now you can use this in your script which is assigned to the video plane:

I have just tried what you’ve said but didn’t work… Am I missing something ?

Damn, looks like the trigger needs a rigidbody, well you could create 2 scripts, one script which notifies the other script, the other script could then activate or deactivate the video.